I write my class error handler, in the constructor I implement the following handlers:
set_error_handler([$this, 'errorHandler']); set_exception_handler([$this, 'exceptionHandler']); ob_start(); register_shutdown_function([$this, 'fatalErrorHandler']); In each of these methods, I throw a new exception, for example:
public function fatalErrorHandler() { $error = error_get_last(); if ( !empty($error) && $this->isFatalError($error['type']) ) { ob_get_clean(); throw new ErrorException($error['message'], $error['type']); } else { ob_end_flush(); } } The ErrorException class is the grandson of the base \ Exception:
class ErrorException extends Exception { const RESPONSE_CODE = 500; } class Exception extends \Exception { /* +новые функции */ } Problem: when testing a fatal error handler, for example, when calling a non-existent function, a fatal error crashes:
Fatal error: Uncaught lynx\core\handlers\ErrorException: Uncaught Error: Call to undefined method **Error::array()** in vendor\lynx\core\ErrorHandler.php:124 Stack trace: #0 [internal function]: lynx\core\ErrorHandler->exceptionHandler(Object(Error)) #1 {main} thrown in C:\OpenServer\domains\smart-as.dev\vendor\lynx\core\ErrorHandler.php on line 110 That is, an Error object that I threw out is not thrown to the exception handler, but an Error object. It is clear that he is also a descendant of Throwable, but why does he come then?
If you throw an exception of the global \ Exception object, then it is the same - the same Error comes in the exeptionHandler (code below). I can not understand what the problem is, I do not understand something, but I can not google it.
public function exceptionHandler(Exception $e) { $this->error = $e->array(); $this->displayError($e->getResponseCode()); $this->logErrors(); } Thank you in advance!