I am trying to make an OO application and I am having trouble passing variables down the chain of command of classes. I am trying to create a var in the parent class and then use it again two sub-classes down. Apparantly there is some blockage between passing variables more than one level.
Take a look at this example of what I am trying to do:
<?php
class framework
{
var $test = "Hello World";
}
class controller extends framework
{
}
class sub_controller extends controller
{
function sub_controller()
{
echo($this->test); //This shows up blank (not set)
$this->test = "Another Hello World";
}
}
$fw = new framework();
$c = new controller();
$sc = new sub_controller();
print($fw->test); //Outputs "Hello World", not "Another Hello World"
?>
My question is, how can I use the variables from the parent framework in the sub_controller without having to declare $fw as global inside every function I want to use it in. I know objects are supposed to work together, but apparantly I am missing the key to linking them together.
Also, and almost more importantly, how do I re-assign the value of a parent class variable from a sub-sub class?
Thanks!