在我用PHP开发的这些年里,我总是听说使用eval()是邪恶的.
考虑以下代码,使用第二个(更优雅)选项是否有意义?如果没有,为什么?
// $type is the result of an SQL statement
// e.g. SHOW COLUMNS FROM a_table LIKE 'a_column';
// hence you can be pretty sure about the consistency
// of your string
$type = "enum('a','b','c')";
// possibility one
$type_1 = preg_replace('#^enum\s*\(\s*\'|\'\s*\)\s*$#', '', $type);
$result = preg_split('#\'\s*,\s*\'#', $type_1);
// possibility two
eval('$result = '.preg_replace('#^enum#','array', $type).';');
Run Code Online (Sandbox Code Playgroud) 在PHP中,您有create_function()函数,它创建一个唯一的命名lambda函数,如下所示:
$myFunction = create_function('$foo', 'return $foo;');
$myFunction('bar'); //Returns bar
Run Code Online (Sandbox Code Playgroud)
这实际上是否更好(除了更容易)然后只是做:
do{
$myFunction = 'createdFunction_'.rand();
}
while(function_exists($myFunction));
eval("function $myFunction(\$foo) { return \$foo; }");
$myFunction('bar'); //Returns bar
Run Code Online (Sandbox Code Playgroud)
create_function真的更好吗?(除了事实上它更容易)
ionCube以加密格式存储php文件,它作为php扩展安装,但我想知道的是当我从非加密的php文件请求加密的php文件时,php编译器如何执行它.
它是否将加密文件发送到ionCube服务器并获取原始文件并编译该文件或其他内容.
表示我们的服务器和ionCube之间的通信方式.我想这是通过卷曲但我想知道它是如何工作的.