Cannot redeclare a previously declared function declared only once

I am having a problem with this function from another file

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

When running the script, it gives the following error

Fatal error: Unable to override sendRes () (previously declared in ********** \ email.php: 3) to *********** \ email.php on line 54

But it is declared only once, I checked that the file is included only once. And the file contains only this function.

Any tips on why this is not working?

+4
source share
2 answers

remove the code block that you included and see what the code returns.

var_dump(function_exists('send_res'));

If you are mistaken, you include the file with this function twice, replace:

includec include_onceand replace requirewith require_once.

, 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

if(function_exists('function_name')) {

} 

http://php.net/manual/en/function.function-exists.php

+2

All Articles