In PHP, error_clear_last() erases the record of the most recent error, so that error_get_last() returns null again.
PHP quietly remembers the last error that happened, even when you hide it with the @ operator. That is handy, but an old error can confuse your checks. Calling error_clear_last() before a risky operation gives you a clean slate, so any error you find afterwards is definitely new.
Syntax
Call error_clear_last() with the values you need. Start with this line.
PHP
error_clear_last();
Call
What it does
error_clear_last()
Clears the stored last error. It takes no arguments.
At the start no error has happened, so error_get_last() returns NULL.
var_dump(error_clear_last()) prints NULL because the function returns void.
Only the newest error is remembered, so after two notices the message is Second.
Clearing twice causes no problem, and error_get_last() is NULL again.
Frequently Asked Questions
It clears the information about the most recent error, so error_get_last() returns null until a new error happens.
PHP keeps the last error even if it was hidden or happened a long time ago. If you check error_get_last() after a risky call, you could read an old error by mistake. Clearing it first prevents that.
No. It only resets what error_get_last() reports. Messages that were already written to a log file or to the screen stay there.
No. You simply call error_clear_last() with empty parentheses. It returns nothing.
error_clear_last() forgets the last error that happened. restore_error_handler() changes which function handles future errors. They solve different problems.