我有这个简单的 PHP 代码:
<?php
$code = "echo 'Hello World'; }";
call_user_func(create_function('', $code));
如您所见,我的$code
有语法错误。当我运行它时,我得到了这个结果:
Parse error: syntax error, unexpected '}' in file.php(4) : runtime-created function on line 1
Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in file.php on line 4
如何将Parse 错误转换为变量?例如:
$error = some_func_to_get_error();
echo $error;
// Parse error: syntax error, unexpected '}' in file.php(4) : runtime-created function on line 1