Page 1 of 1

capturing "Fatal error: Call to undefined function xxx&

Posted: Fri Jan 04, 2008 3:59 pm
by mechamecha
Hello,
I'm writing my own error logging handler function that writes php errors to disk. I cannot figure out how to capture errors that come from calling an undefined function or malformed php statements. If I set php to display all errors, I can see these errors displayed on my browser, however these errors don't appear to invoke my error handler function.

Here are the php calls I'm making to setup my error logger:

Code: Select all

ini_set( 'error_reporting', E_ALL );
ini_set( 'display_errors', 'Off' );
ini_set( 'log_errors', 'On' );

// the error logging function
function myErrorHandler( $p_number, $p_string, $p_file, $p_line, $p_context )
{
// ...
}

set_error_handler( 'myErrorHandler' );
Am I missing something here?

THanks

Posted: Fri Jan 04, 2008 5:00 pm
by alex.barylski
The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

Posted: Fri Jan 04, 2008 5:35 pm
by mechamecha
Thanks for the heads up Hockey!

In that case, is there any way to get these particular error types logged to disk? Can I get the default error logger to log these errors to disk?

Posted: Fri Jan 04, 2008 5:47 pm
by alex.barylski
I have to ask why you would want to log that kind of error...compile time errors are really only of interest once and should be fixed ASAP and forgotten.

Missing functions are possibly somethign worth logging, in the case where you have dynamically loaded modules, etc...

In this case, I wouldn't rely on error logging but rather a conditional check to see if the function/method/class exists and if not, log the error and throw an exception...

Code: Select all

$function = 'do_something';
if(function_exists($function)){
  // Do something
}
else{
  echo "Function: $function didn't exist";
}

Posted: Fri Jan 04, 2008 8:27 pm
by mechamecha
Yeah, normally I wouldn't care to log such errors. However, recently I had to spend a whole day tracking a bug due to a missing function. The problem was really due to the fact that my development environment was running a later version of php than my production environment. A rookie mistake, but having php log an error to disk for an unrecognized function would have been nice.

Posted: Fri Jan 04, 2008 9:17 pm
by feyd
Set the error_log configuration setting.