PHP OOP: Issues with properties and extended class

Let’s say I have this PHP script:


class Aaa
    protected $var = null;

    public function performSomething()
        $this->var = 'Now we have a string, not more null value';
        $bbb = New Bbb();


class Bbb extends Aaa
    public function powerOnYou()
        // this dump "NULL" and not string

$aaa = New Aaa();

How you can note this class will “var_dump” everytime NULL, and not the string.

Of course I need to output the string.

This is also the sandbox link:

Thank you

Source: oop

Leave a Reply