Pero si lo estoy diciendo desde el principio. Mira el ejemplo
Código PHP:
Ver original<?php
// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno) {
case E_USER_ERROR:
echo "<b>My 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";
break;
case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
// function to test the error handling
function scale_by_log($vect, $scale)
{
trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR); }
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING); return null;
}
foreach($vect as $pos => $value) {
trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE); $value = 0;
}
$temp[$pos] = log($scale) * $value; }
return $temp;
}
// set to the user defined error handler
// trigger some errors, first define a mixed array with a non-numeric item
echo "vector a\n";
$a = array(2, 3, "foo", 5.5, 43.3, 21.11);
// now generate second array
echo "----\nvector b - a notice (b = log(PI) * a)\n";
/* Value at position $pos is not a number, using 0 (zero) */
$b = scale_by_log($a, M_PI);
// this is trouble, we pass a string instead of an array
echo "----\nvector c - a warning\n";
/* Incorrect input vector, array of values expected */
$c = scale_by_log("not array", 2.3);
// this is a critical error, log of zero or negative number is undefined
echo "----\nvector d - fatal error\n";
/* log(x) for x <= 0 is undefined, you used: scale = $scale" */
$d = scale_by_log($a, -2.5);
En el switch menciona el primer case como
E_USER_ERROR, eso es un error fatal y hasta el echo lo menciona. Sí se puede verificar algunos errores fatales, pero al parecer el error de funciones no definidas anteriormente no es posible. En ese caso hay que hacer lo que tu llamas hacks.