【发布时间】:2010-10-15 02:39:15
【问题描述】:
我正在尝试通过使用变量类名来访问类中的静态变量。我知道,为了访问类中的 函数,您使用 call_user_func():
class foo {
function bar() { echo 'hi'; }
}
$class = 'foo';
call_user_func(array($class, 'bar')); // prints hi
但是,当尝试访问类中的静态变量时,这不起作用:
class foo {
public static $bar = 'hi';
}
$class = "foo";
call_user_func(array($class, 'bar')); // nothing
echo $foo::$bar; // invalid
我如何得到这个变量?甚至可能吗?我有一种不好的感觉,这仅在 PHP 5.3 中可用,而我正在运行 PHP 5.2.6。
【问题讨论】:
-
@Krinkle,请不要养成在文本中添加粗体的习惯——它对很多人的帮助几乎没有。谢谢!
标签: php