When I call a method on a property instantiated in a parent class’ constructor as follows:
class A
{
function AA()
{
}
}
class C
{
function __construct()
{
$this->A = new A();
}
}
class B extends C
{
function __construct()
{
$this->A->AA();
}
}
I get this error:
Fatal error: Call to a member function AA() on a non-object in…
Why is that?
Because constructors don’t call parent constructors by default. You can trigger it with
parent::__construct().