PHP Function Reference

PHP error_clear_last() Function



The PHP error_clear_last() function is used to clear the most recent error.

Syntax

error_clear_last()

Parameters

No parameter is required.

Return Value

Clears the most recent errors, making it unable to be retrieved with error_get_last().

Example: error_clear_last() example

The example below shows the usage of error_clear_last() function.

<?php
//getting last occurred error
var_dump(error_get_last());

//assigning value from undefined variable
@$a = $b;

//getting last occurred error
var_dump(error_get_last());

//clearing the last occurred error
error_clear_last();

//after clearing the last occurred
var_dump(error_get_last());
?>

The output of the above code will be:

NULL
array(4) {
  ["type"]=>
  int(2)
  ["message"]=>
  string(21) "Undefined variable $b"
  ["file"]=>
  string(39) "Main.php"
  ["line"]=>
  int(6)
}
NULL

❮ PHP Error Handling Reference