The next code:
$a["x"];//should trigger notice
var_dump(error_get_last());//return the error array
runs perfectly and returns an error array.
but when I use set_error_handler it returns null
function _do_nothing(){}
set_error_handler('_do_nothing');
$a["x"];//should trigger notice
var_dump(error_get_last());//return null
This code works perfectly on PHP5.4 I had changed 3 month ago to PHP7 and since then I am getting nulls in error_get_last()
I am using a shutdown function to check if an error has occured and if so to send it to the developer.
- Is there a way to make this code run in PHP7? and make error_get_last() works with set_error_handler()?
- Any other ideas for workaround? and make a shutdown function get the last error? I am using CodeIgniter, and prefer not to hack their internal code.
This is normal behavior because in your example the error is already handled by the
_do_nothing()
function, so theerror_get_last()
returnsnull
if you remove
set_error_handler('_do_nothing')
the error won't be handled anymore and you will get the last error againThis behavior is the same in PHP5 as in PHP7