这与function_exists returns false but declaration throws error类似,但我认为这不是命名空间的问题,因为它是内部函数,而不是用户函数,它给了我这个问题。
我在我的php应用程序中使用dompdf,而他们的dompdf类中的以下函数导致我出现问题....
if ( !function_exists('sys_get_temp_dir')) {
/**
* Find the current system temporary directory
*
* @link http://us.php.net/manual/en/function.sys-get-temp-dir.php#85261
*/
function sys_get_temp_dir() {
if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
$tempfile=tempnam(uniqid(rand(),TRUE),'');
if (file_exists($tempfile)) {
unlink($tempfile);
return realpath(dirname($tempfile));
}
}
}
我得到的是
Fatal error: Cannot redeclare sys_get_temp_dir() on line 873
当我使用get_defined_functions()方法回显时,它向列表的末尾显示函数sys_get_temp_dir,所以它甚至不应该进入我不会想到的if语句?
答案 0 :(得分:1)
对于那些不想深入评论的人:
如果通过php.ini文件禁用某个函数,即通过disable_functions
指令中的命名,function_exists
函数将返回false
,但仍然不允许重新声明该函数。只需从disable_functions
列表中删除该功能,代码就会按预期工作。
您可以通过在测试页上运行phpinfo()
,或者在测试页上运行该功能并查看错误日志来检查这是否是您的问题。实际上运行该函数会在错误日志中显示一条消息,出于安全原因,该函数已被禁用。