I have been using OOP in PHP for a while, but for some reason I have a general brain crisis and cannot understand what is going wrong here!
I have a much more complex class, but he wrote a simpler one to test it, and even that doesn't work ...
Can someone tell me what I am doing wrong?
class test
{
public $testvar;
function __construct()
{
$this->testvar = 1;
}
}
class test2 extends test
{
function __construct()
{
echo $this->testvar;
}
}
$test = new test;
$test2 = new test2;
All I am trying to do is pass a variable from the parent class to the child class! I swear in the past I used $ this-> varName to get $ varName in the extension
Thanks!
source
share