May 12, 2007 4:24:24 GMT -5
Hello,
In this tut I'll try and explain the function: set_error_handler().
With this function you can define your own errors if something goes wrong in your coding. Instead of the standard PHP errors, you can get your own (stylish) errors.
You start of making a function, wich handles the errors. Here's an example:
function errorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno) {
case E_USER_ERROR:
echo "<b>ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
case E_USER_WARNING:
echo "<b>WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
// Return true so the PHP errors won't come up.
return true;
}
You see that you can add Notice, Warning and User(FATAL) errors in this example.
$errno is the error number. Depends on what the problem is.
$errstr holds the error message.
Now you want it to use your own made error handler:
<?php
$error_handler = set_error_handler( "errorHandler" );
?>
Now it will give the errors in the function when your coding isn't right.
Here's a list of all possible errors to handle:
E_ERROR
E_WARNING
E_PARSE
E_NOTICE
E_CORE_ERROR
E_CORE_WARNING
E_COMPILE_ERROR
E_COMPILE_WARNING
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
E_STRICT
E_RECOVERABLE_ERROR
Hope it helps, have fun
Greetings,
Mike.
We'll burn that bridge when we come to it.
サイミ 🐍
snake
neurotic + overseer
Moderator
May 12, 2007 4:28:43 GMT -5
Very nice tutorial, good job