Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem, I think, lies here:</p> <p>If you consider a simple inheritance like this one:</p> <pre><code>class Dog{ public $color; public function __construct($color){ $this-&gt;color = $color; } } class TrainedDog extends Dog{ public $tricks; public function __construct($color, $tricks){ $this-&gt;tricks = $tricks; parent::__construct($color); } } //Create Dog: $alfred = new Dog('brown'); //Create TrainedDog $lassie = new TrainedDog('golden',array('fetch')); </code></pre> <p>In this example $alfred is a brown dog and $lassie is a golden dog. The two instances are separate from each other, the only thing they have in common is that they both have a property called $color.</p> <p>If you want a variable that is available in all Dogs for example, you need a class variable:</p> <pre><code>class Dog{ public $color; public static $numberOfLegs; //Class variable available in every instance of Dog. public function __construct($color, $numberOfLegs){ $this-&gt;color = $color; self::$numberOfLegs = $numberOfLegs; } } class TrainedDog extends Dog{ public $tricks; public function __construct($color, $tricks){ $this-&gt;tricks = $tricks; parent::__construct($color); echo parent::$numberOfLegs; } } </code></pre> <p>This does not make much sense in many cases though, because if you have two instances of the parent class (in you're case Core), they also share the class variable.</p> <p>Unless you can ensure that Core is instanciated only once, this approach will not work. If it does only exist once, you can just as well use constant variables to store the 2 properties.</p> <p>If there exist multiple instances/objects of Core, I'd recommend using a composition (as suggested by Alvin Wong).</p> <pre><code>class Core{ //Just as you programmed it. } class Property{ private $core; public function __construct($core){ $this-&gt;core = $core; echo $core-&gt;curPath; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload