Why is the Username constructor private? If you mean to make it impossible to create a Username, make the Username class abstract. Also, do NOT make a new contact information from the parent class. Here's another way to put it:
abstract class Username {
protected $id;
protected $username;
public __construct($id) {
$this->id = (int) $id; // Forces it to be a string
}
}
class ContactInformation extends Username {
protected $mobile;
protected $email;
protected $nextel_id;
public __construct($id, $mobile, $email, $nextel_id) {
parent::__construct($id)
$this->mobile = $mobile;
....
}
}
Now, instead of instantiating the Username directly (which is now impossible), you instead create a ContactInformation. ContactInformation then calls the Username constructor in its own constructor.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…