【发布时间】:2009-05-06 20:21:42
【问题描述】:
我上了这门课:
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 和 $username(以及许多其他变量),但是 parent:: 或 $this-> 不起作用,看起来就像每次我执行“new ContactInformation.. ..) PHP 创建一个“新用户名”。有机会从用户名访问当前值吗?
谢谢
【问题讨论】:
-
我认为你需要从头开始阅读类扩展和抽象。
-
"private __construct" uff.