Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 函数_exists返回false,但不能重新声明函数_Php_Dompdf - Fatal编程技术网

Php 函数_exists返回false,但不能重新声明函数

Php 函数_exists返回false,但不能重新声明函数,php,dompdf,Php,Dompdf,这与类似,但我不认为名称空间有问题,因为它的内部函数,而不是用户函数,给了我这个问题 我在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

这与类似,但我不认为名称空间有问题,因为它的内部函数,而不是用户函数,给了我这个问题

我在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()
或在测试页上运行函数并查看错误日志来检查这是否是您的问题。实际运行该函数将在错误日志中显示一条消息,表明该函数已因安全原因被禁用。

对于不希望深入查看注释的用户:

如果通过php.ini文件禁用函数,即通过在
disable_functions
指令中命名,则
function_exists
函数将返回
false
,但仍不允许重新声明该函数。只需从
disable_functions
列表中删除该功能,代码即可正常工作


您可以通过在测试页上运行
phpinfo()
或在测试页上运行函数并查看错误日志来检查这是否是您的问题。实际运行该函数时,会在错误日志中显示一条消息,说明该函数因安全原因已被禁用。

第873行是上面显示的函数声明吗?当然,函数sys_get_temp_dir()是第873行,我知道这不能回答你的问题,但是,由于这个函数实际上是在你运行的PHP版本中定义的,所以你可以删除整个代码块。如果你只关心让你的应用程序工作,那就应该做到。很有趣。。。注释掉代码会带来另一个错误,这可能是发生这种情况的原因:警告:出于安全原因,在以下行中禁用了sys_get_temp_dir():def(“dompf_temp_dir”,sys_get_temp_dir());我刚刚评论过,然后我们就走了。。。干杯仅供参考,您需要临时目录进行图像处理和URL文件访问。您可以手动定义临时目录。建议您使用dompdf_config.custom.inc.php修改配置。修改相关行,使其类似于
define('dompd_TEMP_DIR','/path/to/writeable/directory')。第873行是上面显示的函数声明吗?当然,函数sys_get_temp_dir()是第873行,我知道这不能回答你的问题,但是,由于这个函数实际上是在你运行的PHP版本中定义的,所以你可以删除整个代码块。如果你只关心让你的应用程序工作,那就应该做到。很有趣。。。注释掉代码会带来另一个错误,这可能是发生这种情况的原因:警告:出于安全原因,在以下行中禁用了sys_get_temp_dir():def(“dompf_temp_dir”,sys_get_temp_dir());我刚刚评论过,然后我们就走了。。。干杯仅供参考,您需要临时目录进行图像处理和URL文件访问。您可以手动定义临时目录。建议您使用dompdf_config.custom.inc.php修改配置。修改相关行,使其类似于
define('dompd_TEMP_DIR','/path/to/writeable/directory')