Set values of grandparent from child's child

I get Unknown Property error:

Setting unknown property: app\models\grandparent ::grandparent_column1

on trying to do, as mentioned below:





class grandparent extends ActiveRecord{

public function setvalue(){

$this->grandparent_column1 = "abc";

 }

}


class parent extends grandparent{

public function setvalue(){

parent::setvalue();

$this->parent_column1 = "def"

 }

}


class child extends parent{

public function setvalue(){

parent::setvalue();

$this->child_column1 = "xyz";

 }

}


$child_object = new child();

$child_object->setvalue;

echo $this->child_column1;

echo $this->parent_column1;

echo $this->grandparent_column1;



Please let me know, how can this be achieved?

Hi,

For the sake of learning:




class GrandParentClass 

{

    public $grandparent_column1;

    

    public function setvalue()

    {

        $this->grandparent_column1 = "abc";

    }

}


class ParentClass extends GrandParentClass

{

    public $parent_column1;

    

    public function setvalue()

    {

        parent::setvalue();

        $this->parent_column1 = "def";

    }

}


class ChildClass extends ParentClass

{

    public $child_column1;

    

    public function setvalue()

    {

        parent::setvalue();

        $this->child_column1 = "xyz";

    }

}


$childObject = new ChildClass();

$childObject->setvalue();

echo $childObject->child_column1;

echo $childObject->parent_column1;

echo $childObject->grandparent_column1;



I highly suggest you to learn about PHP & OOP basics first.

Or at least follow some basic tutorials.

You find plenty with google just look for "PHP OOP Beginner Tutorials".

Regards