odbc_errormsg
does not report odbc_execute
error messages as intended. He just warns. So I was forced to write a hack to parse the error message through error_get_last
.
I use set_error_handler
and error_get_last
returns NULL
if I, too:
disable my error handler
or return it to FALSE
.
I would suggest that this is due to the PHP builtin error handler, which takes care of storing the error data somewhere so that it can be found later.
Is there a way to emulate this behavior in my custom error handler, so error_get_last()
can be used normally?
Please note: I already know several ways to get error information at any time. My question is how to make error_get_last
useful.
Update: I think I better place the code.
PHP has error_get_last()
, which allows you to do this:
@fopen('xxx'); var_dump( error_get_last() );
... and get the following:
array(4) { ["type"]=> int(2) ["message"]=> string(46) "fopen() expects at least 2 parameters, 1 given" ["file"]=> string(69) "C:\Documents and Settings\ALVARO.GONZALEZ\Mis documentos\tmp\test.php" ["line"]=> int(3) }
This breaks if you replace the built-in error handler:
function custom_error_handler($errno, $errstr, $errfile, $errline){ $ignore = ($errno & error_reporting()) == 0; if(!$ignore){ echo "[Error happened: $errstr]\n"; } return TRUE; } set_error_handler('custom_error_handler'); @fopen('xxx'); var_dump( error_get_last() );
If you save both error handlers ...
function custom_error_handler($errno, $errstr, $errfile, $errline){ $ignore = ($errno & error_reporting()) == 0; if(!$ignore){ echo "[Error happened: $errstr]\n"; } return FALSE; } set_error_handler('custom_error_handler'); error_reporting(E_ALL); echo $foo;
... you get side effects:
[Error happened: Undefined variable: foo] Notice: Undefined variable: foo in C:\Documents and Settings\ALVARO.GONZALEZ\Mis documentos\tmp\test.php on line 15 Call Stack: 0.0004 329720 1. {main}() C:\Documents and Settings\ALVARO.GONZALEZ\Mis documentos\tmp\test.php:0
... instead of just:
[Error happened: Undefined variable: foo]
I want my custom error handler to interact correctly with error_get_last
. I want error_get_last
work fine.