Hi, all
I want to write my own error handler function in php by using
"set_error_handler()" function. I have made a test for this function but
found it did not work. My test code is as following:
<?php
function myerrorHandler ($errno, $errstr, $errfile, $errline,
$errcontext)
{
switch ($errno)
{
case E_USER_WARNING:
case E_USER_NOTICE:
case E_WARNING:
case E_NOTICE:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_ERROR:
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
echo "This is my own error handler
function\n";
die();
}
}
set_error_handler("myerrorHandler");
Undefined();
?>
In the code, "Undefined()" is a function which is not defined in the
file, so it should produce a error message.
If my own handler function works, it should print "This is my own error
handler function". but actually, when my program runs, it gives the
error report:
"Fatal error: Call to undefined function: undefined() in
/var/www/localhost/htdocs/hello.php on line 28"
which means handler function doesn't work.
What is wrong? why the function "set_error handler" can not work?
Thanks for your suggestion!