I have a class Second
in which is initiated through First
. I'm trying to access $variable
directly, which I should be able to do with $this->variable
, however it doesn't seem to work.
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();
Outputs: test
, should output 123test
?
Note: I made the functions public for testing purposes. I'm really trying to access the variable directly rather than passing it through a __construct
.