I have set up my code to use an error handling class that I created. For some reason, a particular bit of code causes an E_NOTICE error that halts code execution without any error message.
My code init does this:
// *** INIT.PHP ***
require_once($path_to_web_root . "includes/error_handler.php");
// by instantiating this class, we set up php to use my function
// to handle errors and acquire considerable control over
// how non-critical errors are handled
$error_handler = new error_handler();
the file error_handler.php sets up custom error handling like this:
// *** INCLUDES/ERROR_HANDLER.PHP ***
class error_handler {
// list of vars....blah blah blah
// constructor
function error_handler() {
// initialize various vars....blah blah blah
set_error_handler(array(&$this, 'error_handler_function'));
register_shutdown_function(array(&$this, 'error_handler_shutdown'));
} // error_handler()
function error_handler_function($error_type,
$error_msg,
$error_file,
$error_line,
$error_context,
$extra_info='') {
global $log;
$log->write('==== ERROR HANDLER FUNCTION: ====');
$log->write(' type: ' . $this->get_error_type_text($error_type));
$log->write(' mesg: ' . $error_msg);
$log->write(' file: ' . $error_file);
$log->write(' line: ' . $error_line);
$log->write(' cont: ' . $error_context);
$log->write(' extr: ' . $extra_info);
// blah blah blah blah code here to log/email/halt depending on my preferences
// i put this line here so i could be sure the routine wasn't halting execution
echo 'here we are....just make sure nothing halting<br>';
return true;
} // error_handler_function()
} // class error_handler
this seems to work great under most conditions, however, ONE TINY ERROR in a particular class i've written causes an E_NOTICE error and for some reason code execution stops after that. when i access my main script, I get 2 E_STRICT notices which are handled identically to E_NOTICE and then i get a single E_NOTICE that halts code execution for some reason.
the page outputs this:
here we are....just make sure nothing halting
here we are....just make sure nothing halting
here we are....just make sure nothing halting
these correspond to my error handling function getting called 3 times for small notices and tells me that my error handling function s running all the way through and returning true. the log file says:
LOG CREATED 12 15 2006
==== ERROR HANDLER FUNCTION: ====
type: E_STRICT
mesg: date() [<a href='function.date'>function.date</a>]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead
file: /var/www/html/includes/functions.php
line: 191
cont: Array
extr:
==== ERROR HANDLER FUNCTION: ====
type: E_STRICT
mesg: strtotime() [<a href='function.strtotime'>function.strtotime</a>]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead
file: /var/www/html/includes/functions.php
line: 199
cont: Array
extr:
==== ERROR HANDLER FUNCTION: ====
type: E_NOTICE
mesg: Undefined variable: random_search_limit
file: /var/www/html/includes/search.php
line: 60
cont: Array
extr:
That last E_NOTICE, the one halting execution for some reason is caused by a class i've defined which is called from my main script like this:
// *** MAIN_SCRIPT.PHP ***
include('includes/search.php');
$gs = new search();
that class looks like this...it's the accidental reference to an undefined $var that causes the problem:
// *** INCLUDES/SEARCH.PHP ***
class search {
var $var1;
var $var2;
var $var3
function search() {
$this->var1 = 'foo';
$this->var2 = 'bar';
$this->$var3 = 'zoiks!'; // that dang dollar sign was a mistake
}
} // session_class()
It would seem that the notice which is entirely valid results in my error handler getting called which runs to completion and then suddenly code just halts for no reason.
why might this be?