I am trying to access a static variable within a class by using a variable class name. I'm aware that in order to access a function within the class, you use call_user_func()
:
class foo {
function bar() { echo 'hi'; }
}
$class = 'foo';
call_user_func(array($class, 'bar')); // prints hi
However, this does not work when trying to access a static variable within the class:
class foo {
public static $bar = 'hi';
}
$class = "foo";
call_user_func(array($class, 'bar')); // nothing
echo $foo::$bar; // invalid
How do I get at this variable? Is it even possible? I have a bad feeling this is only available in PHP 5.3 going forward and I'm running PHP 5.2.6.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…