raygun Posted May 21, 2015 Share Posted May 21, 2015 I must be missing something very basic but I'm stuck after several hrs of trying various solutions to this apparent function re-declaration in my config.inc.php file. Possibly after staring at the code for so long I just can't see it any more. But, I keep getting an error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\muztash\config\config.inc.php:64) in C:\xampp\htdocs\muztash\config\config.inc.php on line 91 The error seems to say that the function is being declared twice on the same page. Line 64 is the 1st line of the actual declaration: function my_error_handler($e_number,$e_message,$e_file,$e_line,$e_vars) { Line 91 is the ending } of the declaration. It matches the opening { on line 64 and there are no brace mismatches inside the declaration - which pretty closely follows the example code in the book. I have a couple of other questions but I'll focus on this one first. Thanks to whoever can help me with this. Link to comment Share on other sites More sharing options...
Larry Posted May 22, 2015 Share Posted May 22, 2015 Could you post your entire config.inc.php? Wrap the code in the code tags (the angle brackets) to make it easier to view. Thanks! Link to comment Share on other sites More sharing options...
sorin Posted July 3, 2015 Share Posted July 3, 2015 Larry i got the same error at this file. Fatal error: Cannot redeclare my_error_handler() (previously declared in C:\wamp\www\php-advance-programmig\ch02\config.inc.php:54) in C:\wamp\www\php-advance-programmig\ch02\config.inc.php on line 80 And the 2nd error Notice: Undefined variable: p in C:\wamp\www\php-advance-programmig\ch02\config.inc.php on line 40 <?php //Errors are emailed here $contact_email = 'example@example.com'; //Determine if you are working on a local server //Or a real server $host = substr($_SERVER['HTTP_HOST'], 0, 5); if(in_array($host, array('local', '127.0', '192.1'))) { $local = TRUE; } else { $local = FALSE; } if($local) { //Always debug when running locally $debug = TRUE; //Define de constants //BASE_URI is the absolute file system path to where the site's root folder is on server define('BASE_URI', 'C:/wamp/www/php-advance-programmig/ch02/'); //The host name and directory define('BASE_URL', 'http://localhost/php-advance-programmig/ch02/'); //The absolute path to the file that contains the database connectivity information define('DB', 'C:/wamp/www/php-advance-programmig/ch02/'); } else { define('BASE_URI', 'path/to/live/html/folder/'); define('BASE_URL', 'http://example.com/'); define('DB', 'path/to/live/mysql.inc.php'); } //The $debug variable si used to set error management //To debug a specific page, add this to the index.php page if($p == 'thismodule') $debug = TRUE; require 'config.inc.php'; //To debug entire site, do $debug = TRUE; //Before this next conditional //Assume debugging is off if(!isset($debug)) { $debug = FALSE; } //Create the error handler function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) { global $debug, $contact_email; //Build the error message $message = "An error occurred in script '$e_file' on line $e_line: $e_message"; //Append $e_vars to the $message $message .= print_r($e_vars,1); if($debug) { //Show error echo '<div class="error">' . $message . '</div>'; debug_print_backtrace(); } else { //Log the error error_log($message, 1, $contact_email); //Send the email //Only print an error message if the error isn't a notice or strict if(($e_number != E_NOTICE) && ($e_number < 2048)) { echo '<div class="error"> A system error occured. We apologize for tthe inconvenience.</div>'; } } }//End of my_error_handler() definition //Use the error handler set_error_handler('my_error_handler'); Link to comment Share on other sites More sharing options...
Larry Posted July 4, 2015 Share Posted July 4, 2015 You have several lines in your code that are live that are commented out in the book. This includes this line: require 'config.inc.php'; which obviously shouldn't be within the config file (it's a comment on how this file is included in OTHER files). Link to comment Share on other sites More sharing options...
sorin Posted July 10, 2015 Share Posted July 10, 2015 Thank you Larry for help. I didn't pay attention Link to comment Share on other sites More sharing options...
Recommended Posts