这
类似于返回 false function_exists但声明抛出错误,但我认为这不是命名空间的问题,因为它是内部函数,而不是用户函数,这给了我问题。
我在我的 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 语句??
对于不想挖掘评论的人:
如果通过 php.ini 文件禁用函数,即通过在 disable_functions
指令中命名,function_exists
函数将返回 false
,但仍然不允许重新声明该函数。只需从disable_functions
列表中删除该函数,代码将按预期工作。
您可以通过在测试页上运行phpinfo()
或在测试页上运行函数并查看错误日志来检查这是否是您的问题。实际运行该函数会在错误日志中显示一条消息,指出出于安全原因已禁用该功能。