が、私はこのクラスを得た:PHPの子クラスへのアクセス親変数問題
Class Username {
protected $id;
protected $username;
protected $contact_information;
private __construct($id) {
$this->id = (int) $id; // Forces it to be a string
$contact_information = new ContactInformation($this->id);
}
}
Class ContactInformation extends Username {
protected $mobile;
protected $email;
protected $nextel_id;
.....
}
私の問題は、次のとおりです。私はContactInformation上の$ idと$ユーザ名(および他の変数の多く)にアクセスしたいのですが、親::もしくはます$ this->は動作しませんが、私は毎回のように見えます。ユーザー名から現在の値にアクセスするために、任意のチャンス。新しいユーザー名 『「新しいContactInformationを....)PHPが作成されます』?
おかげ
私はあなたが最初からクラスの拡張と抽象を読むために必要があると思います。 – OIS
"private __construct" uff。 –