我有脑膜炎,我怀疑这个很简单。 考虑以下代码,有两个类:为什么我的PHP子类没有从父类获得公共和受保护的变量?
<?php
class myparentclass {
protected $vara;
private $varb;
public $varc;
public $_childclass;
function __construct() {
$this->vara = "foo";
$this->varb = "bar";
$this->varc = ":(";
$this->_childclass = new mychildclass;
}
}
class mychildclass extends myparentclass {
function __construct() {
print_r ($this);
}
}
print "<pre>";
$foo = new myparentclass();
输出是:
mychildclass Object
(
[vara:protected] =>
[varb:private] =>
[varc] =>
[_childclass] =>
)
我知道$ varb不应设置,但对于其他人呢?
告诉你这很简单! +1全部,谢谢。 – 2011-05-25 13:23:56