odbc_errormsg
does not report error messages from odbc_execute
the way it's supposed to. It merely throws a warning. So I've been forced to write a hack to parse the error message via error_get_last
.
I'm using set_error_handler
and error_get_last
returns NULL
unless I either:
disable my error handler,
or make it return
FALSE
.
I'd suppose this is due to PHP's builtin error handler taking care of storing the error details somewhere so they can be retrieved later.
Is there a way to emulate such behaviour in my custom error handler so error_get_last()
can be used normally?
Please note I already know several ways to retrieve error info at any time. My question is how to make error_get_last
usable.
Update: I think I'd better post some code.
PHP has error_get_last()
, which allows to do this:
@fopen('xxx');
var_dump( error_get_last() );
... and get this:
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 builtin 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() ); // NULL
If you keep 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 to my custom error handler to interface properly with error_get_last
. I want error_get_last
to work fine.