error_clear_last
error_clear_last()
Clears the record of the last error message. The error_get_last() function then returns null until the next message occurs. It returns nothing.
Examples
@file_get_contents("/garth-neexistuje.txt");
var_dump(error_get_last() !== null); // bool(true)
error_clear_last();
var_dump(error_get_last()); // NULL
// finding out whether this very statement caused an error
error_clear_last();
$value = @unserialize("x");
echo error_get_last() === null ? "no error" : "error"; // error
error_clear_last();
$value = @unserialize(serialize(5));
echo error_get_last() === null ? "no error" : "error"; // no error
Things to watch out for
- Call it right before the statement whose error you are checking. Otherwise error_get_last() can return an older message from another part of the script.
- It returns nothing (null).
- Exceptions do not concern error_get_last(), they clear nothing.
Related functions:
error_get_last()
set_error_handler()
error_reporting()
unserialize()