例子,
$data="array('key1'=>'value1','key2'=>'value2','key3'=>'value3','key4'=>'value4')";
$arr = eval("return $data;");
var_dump($arr);//array
/*
array
'key1' => string 'value1' (length=6)
'key2' => string 'value2' (length=6)
'key3' => string 'value3' (length=6)
'key4' => string 'value4' (length=6)
*/
网上很多说使用disable_functions禁止掉eval的方法都是错误的!
其实eval()是无法用php.ini中的disable_functions禁止掉的 :
because eval() is a language construct and not a function
eval是zend的,因此不是PHP_FUNCTION 函数;
那么php怎么禁止eval呢?
如果想禁掉eval可以用php的扩展 Suhosin:
安装Suhosin后在php.ini中load进来Suhosin.so,再加上suhosin.executor.disable_eval = on即可