2015-04-17 96 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