2015-04-17 67 views
5

我想用那样的eval()函数:未定义函数eval() - PHP

$foo = 'eval'; 
$bar = 'echo 1;'; 
$foo($bar); 

但我发现了一个错误:致命错误:调用未定义的函数eval()

,由于下面的代码工作它

$foo = 'base64_encode'; 
$bar = 'foobar'; 
echo $foo($bar); 

谁能帮助奇怪?

+1

这是因为它是邪恶的! – adeneo

回答

9

eval documentation

Note: Because this is a language construct and not a function, it cannot be called using variable functions .

继在注意链接,你还会发现:

Variable functions won't work with language constructs such as echo , print , unset() , isset() , empty() , include , require and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

+1

@ficuscr'eval'可以有非常实用和有用的用途。问题是它被滥用。 – Anonymous

+0

勉强同意...虽然他们很少,而且很远。而不是以这种方式 - 很确定变量函数不是为了可读性。查看更多有效的'goto'用例... – ficuscr