Php 无法重新声明以前声明的函数,仅声明一次

Php 无法重新声明以前声明的函数,仅声明一次,php,Php,我在另一个文件中包含此函数时遇到问题 function sendRes($s_attachment) //this is line 3 { /*Snip : processing message details..*/ try { mail($to, $subject, $message, $headers); } catch (Exception $e) { logMessage("An error occured:" . $e->

我在另一个文件中包含此函数时遇到问题

function sendRes($s_attachment) //this is line 3
{
   /*Snip : processing message details..*/

    try {
        mail($to, $subject, $message, $headers);
    } catch (Exception $e) {
        logMessage("An error occured:" . $e->getMessage());
    }
} //this is line 54
运行脚本时,它会输出以下错误

致命错误:无法重新声明sendRes()(以前在中声明 **********\email.php:3)在第54行的*********\email.php中

但是它只声明了一次,我检查了文件是否也只包含一次。并且该文件仅包含此函数

有什么线索可以解释为什么这不起作用吗?

if(function_exists('function_name')) {

} 

删除包含的代码块,然后查看下面的代码返回的内容

var_dump(函数_存在('send_res'))

如果设置为false,则表示该文件包含该函数两次,替换为:

使用
包含
一次
并将
要求
替换为
要求

另一种选择是,将代码放在以下if语句中:

if (!function_exists('sendRes')) {
    function sendRes($s_attachment) //this is line 3
    {
        /*Snip : processing message details..*/

        try {
            mail($to, $subject, $message, $headers);
        } catch (Exception $e) {
            logMessage("An error occured Sending fingerprint:" . $e->getMessage());
        }
    } //this is line 54
}

你能在那个文件中同时发布第3行和第54行吗?你在多个部分使用require“email.php”?如果您尝试在所有这些情况下使用require_一次,这将非常好。同意。在您拉入email.php的实例中,您应该替换为
require\u once
。我只使用了一次,之所以将其放在单独的文件中,是为了保持原始文件的干净,因为该函数使用了大量本地字符串。您要找的函数是
function\u exists
-先生,您应该得到一杯啤酒。虽然不知道第二个include来自何处,但它起了作用。我稍后会进一步调查,但现在,这是我的答案!谢谢!