PHP OOP: Issues with properties and extended class

Let’s say I have this PHP script:

<?php

class Aaa
{
    protected $var = null;

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

    }
}


class Bbb extends Aaa
{
    public function powerOnYou()
    {
        var_dump($this->var);
        // this dump "NULL" and not string
    }
}


$aaa = New Aaa();
$aaa->performSomething();

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: http://sandbox.onlinephpfunctions.com/code/6cd253e1945e78f114749be55ffc5f88ab44dd42

Thank you


Source: oop

Leave a Reply