当前位置: 代码迷 >> PHP >> 变量可以作为方法名吗?该怎么处理
  详细解决方案

变量可以作为方法名吗?该怎么处理

热度:196   发布时间:2012-06-05 13:54:06.0
变量可以作为方法名吗?
PHP code

$name="hello()";
$this->$name;
function hello(){
echo "hello word";
}


大概意思就是上面的代码
请问下有什么方法可以达到这个效果
就是想根据变量的值,不加判断直接调用对应的方法

------解决方案--------------------
PHP code

$name="hello";
$name();
function hello(){
echo "hello word";
}

------解决方案--------------------
$name="hello()";
eval("return $name;");

function hello(){
echo "hello word";
}
  相关解决方案