假设一个具有定义的__get()的抽象基类foo,以及一个从foo继承私有变量$var的子类bar,当尝试从类之外访问私有的$var时,调用父__get() ?
是.
<?PHP abstract class foo { public function __get($var) { echo "Parent (Foo) __get() called for $var\n"; } } class bar extends foo { private $var; public function __construct() { $this->var = "25\n"; } public function getVar() { return $this->var; } } $obj = new bar(); echo $obj->var; echo $obj->getVar(); ?>
输出:
父(Foo)__get()调用var
25