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...

Valkyrurr
  • 119
  • 1
  • 12
  • 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_ – Valkyrurr Jun 28 '16 at 16:21
  • can you please accept my answer as it was correct and first? – catbadger Feb 23 '17 at 19:36

2 Answers2

2

Change your include statement to an include_once.

catbadger
  • 1,662
  • 2
  • 18
  • 27
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.

Sven Tore
  • 967
  • 6
  • 29