php8.5
Home/ Manual/ yaf / yaf_application/ Yaf_Application::clearLastError

Yaf_Application::clearLastError

PHP function Edit on GitHub ✎

(Yaf >=2.1.2)

Clear the last error info

Description

Yaf_Application::clearLastError(): Yaf_Application|null

Clear the code and message of the last error, resetting them to 0 and an empty string. This is useful in error handlers, where a handled error should not be reported again.

Parameters Parameters

Return Values

Returns the Yaf_Application object itself on success, or null if the application is not properly initialized.

Examples

Yaf_Application::clearLastError() example

php
<?php
function error_handler($errno, $errstr, $errfile, $errline) {
   Yaf_Application::app()->clearLastError();
   var_dump(Yaf_Application::app()->getLastErrorNo());
}

$config = array(
 "application" => array(
   "directory" => "/tmp/notexists",
     "dispatcher" => array(
       "throwException" => 0, //trigger error instead of throwing an exception when an error occurs
      ),
  ),
);

$app = new Yaf_Application($config);
$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>

The above example will output something similar to:

output
int(0)

See Also

  • Yaf_Application::getLastErrorNo
  • Yaf_Application::getLastErrorMsg

Source: reference/yaf/yaf_application/clearlasterror.xml · from the official PHP manual (php/doc-en)