Can someone help me understand the inheritance of variables / functions in PHP classes.
My parent class has a function that is used by all child classes. However, each child class must use its own variable in its function. I want to call a function in child classes statically. The example below displays "world" rather than values ββin child classes.
Can anyone explain how I can force the echo value function in child classes. Should I use interfaces? Is this due to late static binding (which is not available to me due to using PHP version 5.3.0)?
class myParent { static $myVar = 'world'; static function hello() { echo self::$myVar; } } class myFirstChild extends myParent { static $myVar = 'earth'; } class mySecondChild extends myParent { static $myVar = 'planet'; } myFirstChild::hello(); mySecondChild::hello();
source share