I’m attempting to access member variables in a child class via the parent class without instantiation.
This is one of my attempts but B::getStatic() fails with Access to undeclared static property.
Is there another solution to this, possibly without static?
class A { static public function getStatic() { return self::$myStatic; } } class B extends A { public static $myStatic = 5; } class C extends A { public static $myStatic = 6; } var_dump(B::$myStatic); var_dump(B::getStatic()); var_dump(C::$myStatic); var_dump(C::getStatic());
The concept you’re running into is called ‘Late Static Binding.’ Until PHP 5.3.0, there was no support for this.
If you’re running 5.3.0 or higher, update the getStatic() method: