我可以在不使用像
这样的危险eval的情况下访问静态类变量$aa = icon;
echo StaticClass::chat{$aa};
equivalent is :
constant("StaticClass::chat$aa")
但是如果staticClass不是静态的,我不知道如何做同样的事情。
即需要访问
$StaticClass->get$aafunc(); // geticonfunc()
请帮忙吗?
答案 0 :(得分:1)
这个怎么样:
<?php
class test {
public static $xyz = "static xyz content";
public static function foo() {
return "result of static foo function";
}
public $wxyz = "wxyz content";
public function bar() {
return "result of bar method";
}
}
$xyzName = "xyz";
$fooName = "foo";
$wxyzName = "wxyz";
$barName = "bar";
$instance = new test();
echo (test::$$xyzName)."<br />";
echo (test::$fooName())."<br />";
echo ($instance->$wxyzName)."<br />";
echo ($instance->$barName())."<br />";
?>
它返回:
static xyz content<br />
result of static foo function<br />
wxyz content<br />
result of bar method<br />