我有一堂课Second
是通过First
. 我正在尝试$variable
直接访问,我应该可以使用$this->variable
它,但是它似乎不起作用。
class First {
public $variable;
public function getSecond() {
$this->variable = '123';
$Second = new Second();
$Second->blah();
}
}
class Second extends First {
public function blah() {
// Trying to access the variable directly, it is not inherited though
print_r($this->variable . 'test');
}
}
$First = new First();
$First->getSecond();
输出:test
,应该输出123test
?
注意:出于测试目的,我公开了这些功能。我真的想直接访问变量,而不是通过__construct
.