I tried many research but I can't find this one. The only problem I am having is that: the $name is empty inside class Daddy.
I tried researching: how to access public variables in extended class but it seems that they haven't done anything like this. I just don't want to re-declare the variables in Grandpa Class. I want it accessible inside Daddy Class.
I have this parent class
<?php
class GrandPa
{
public $name;
public function name($name)
{
$this->name = $name;
return $this;
}
public function get()
{
$daddy = new Daddy;
return $daddy->displayGrandPaName();
}
}
?>
Then the extended one:
<?php
class Daddy extends GrandPa // Inherited class
{
public function displayGrandPaName()
{
var_dump($this->name.'ss');
return $this->name;
}
}
?>
When I initiate:
<?php
$g = new GrandPa;
echo $g->name('aw')->get();
?>
It var dumps:
string(2) "ss"
The expected result would be:
awss