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。