You getting confused between inheritance and aggregation. In your example, you create an instance of DJCms, and then in the constructor you create an instance of bar (which inherits from the class DJCms, but it's not part of the same instance you created earlier. Weedpacket has already shown you how it should be done
class a
{
protected $foo; // Make this protected so child classes can access it
function __construct()
{
$this->foo = "foo";
}
function getFoo()
{
return $this->foo;
}
}
class b extends a
{
function __construct()
{
parent::__construct();
}
function setFoo($var)
{
$this->foo = $var;
}
}
$b = new b;
echo $b->getFoo();
$b->setFoo("bar");
echo $b->getFoo();
Note: I added a getFoo() method since the $foo property is now protected. As a rule properties shouldn't be accessible outside of a class, but it's up to you if you allow it.