1

I have this PHP named logger_error_handler.php required in some other file, say foobar.php. It now flags a redeclaration error.

<?php  
    error_reporting(E_ALL);  
    set_error_handler("logger_error_handler");

    function logger_error_handler($errno, $errstr, $errfile=null, $errline=null, $errcontext=null) {
        $log = date("Y-m-d H:i:s - ");
        $log .= "Error: [". $errno ."], $errstr in $errfile on line $errline, ";
        $log .= "Variables: ". print_r($errcontext, true) ."\r\n";

        error_log($log, 3, "error_log.log");
        die("Error Found!");
    }
?>  

Fatal error: Cannot redeclare logger_error_handler() (previously declared in C:\xampp\htdocs\foo\bar\logger_error_handler.php:5) in C:\xampp\htdocs\foo\bar\logger_error_handler.php on line 12
line 05: referring to function declaration
line 12: referring to closing tag of said function

What am I missing here? Seems no redeclaration to me, yet I can't pin point what's causing it...

2
  • Thanks. I was soooooo focused with what is in Line 05 and 12, I forgot about how require works as opposed to require_once... these ambiguous errors Commented Jun 28, 2016 at 16:21
  • can you please accept my answer as it was correct and first? Commented Feb 23, 2017 at 19:36

2 Answers 2

2

Change your include statement to an include_once.

Sign up to request clarification or add additional context in comments.

Comments

1

you are including logger_error_handler.php from more than one file. One "dirty" option is to change include() to include_once(), or even require_once().

However you should also try an d look at why the file is included more that once, files like this should primarily be included from e.g. a "loader.inc.php" fil etc, that is only called once from every page.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.