You are here

abstract class ErrorHandler in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/debug/ErrorHandler.php \Symfony\Component\Debug\ErrorHandler
  2. 8 vendor/zendframework/zend-stdlib/src/ErrorHandler.php \Zend\Stdlib\ErrorHandler
  3. 8 vendor/symfony/http-kernel/Debug/ErrorHandler.php \Symfony\Component\HttpKernel\Debug\ErrorHandler
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/ErrorHandler.php \Zend\Stdlib\ErrorHandler

ErrorHandler that can be used to catch internal PHP errors and convert to an ErrorException instance.

Hierarchy

Expanded class hierarchy of ErrorHandler

1 file declares its use of ErrorHandler
Reader.php in vendor/zendframework/zend-feed/src/Reader/Reader.php

File

vendor/zendframework/zend-stdlib/src/ErrorHandler.php, line 18

Namespace

Zend\Stdlib
View source
abstract class ErrorHandler {

  /**
   * Active stack
   *
   * @var array
   */
  protected static $stack = [];

  /**
   * Check if this error handler is active
   *
   * @return bool
   */
  public static function started() {
    return (bool) static::getNestedLevel();
  }

  /**
   * Get the current nested level
   *
   * @return int
   */
  public static function getNestedLevel() {
    return count(static::$stack);
  }

  /**
   * Starting the error handler
   *
   * @param int $errorLevel
   */
  public static function start($errorLevel = \E_WARNING) {
    if (!static::$stack) {
      set_error_handler([
        get_called_class(),
        'addError',
      ], $errorLevel);
    }
    static::$stack[] = null;
  }

  /**
   * Stopping the error handler
   *
   * @param  bool $throw Throw the ErrorException if any
   * @return null|ErrorException
   * @throws ErrorException If an error has been catched and $throw is true
   */
  public static function stop($throw = false) {
    $errorException = null;
    if (static::$stack) {
      $errorException = array_pop(static::$stack);
      if (!static::$stack) {
        restore_error_handler();
      }
      if ($errorException && $throw) {
        throw $errorException;
      }
    }
    return $errorException;
  }

  /**
   * Stop all active handler
   *
   * @return void
   */
  public static function clean() {
    if (static::$stack) {
      restore_error_handler();
    }
    static::$stack = [];
  }

  /**
   * Add an error to the stack
   *
   * @param int    $errno
   * @param string $errstr
   * @param string $errfile
   * @param int    $errline
   * @return void
   */
  public static function addError($errno, $errstr = '', $errfile = '', $errline = 0) {
    $stack =& static::$stack[count(static::$stack) - 1];
    $stack = new ErrorException($errstr, 0, $errno, $errfile, $errline, $stack);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ErrorHandler::$stack protected static property Active stack
ErrorHandler::addError public static function Add an error to the stack
ErrorHandler::clean public static function Stop all active handler
ErrorHandler::getNestedLevel public static function Get the current nested level
ErrorHandler::start public static function Starting the error handler
ErrorHandler::started public static function Check if this error handler is active
ErrorHandler::stop public static function Stopping the error handler