Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ErrorHandler.php

class ErrorHandler

Same name in this branch
  1. 11.1.x vendor/phpunit/phpunit/src/Runner/ErrorHandler.php \PHPUnit\Runner\ErrorHandler
  2. 11.1.x vendor/symfony/error-handler/ErrorHandler.php \Symfony\Component\ErrorHandler\ErrorHandler

Convert PHP errors into exceptions

@author Artem Lopata <biozshock@gmail.com>

Hierarchy

  • class \Composer\Util\ErrorHandler

Expanded class hierarchy of ErrorHandler

1 file declares its use of ErrorHandler
Application.php in vendor/composer/composer/src/Composer/Console/Application.php
1 string reference to 'ErrorHandler'
YamlPecl::decode in core/lib/Drupal/Component/Serialization/YamlPecl.php
Decodes data from the serialization format.

File

vendor/composer/composer/src/Composer/Util/ErrorHandler.php, line 22

Namespace

Composer\Util
View source
class ErrorHandler {
    
    /** @var ?IOInterface */
    private static $io;
    
    /**
     * Error handler
     *
     * @param int    $level   Level of the error raised
     * @param string $message Error message
     * @param string $file    Filename that the error was raised in
     * @param int    $line    Line number the error was raised at
     *
     * @static
     * @throws \ErrorException
     */
    public static function handle(int $level, string $message, string $file, int $line) : bool {
        $isDeprecationNotice = $level === E_DEPRECATED || $level === E_USER_DEPRECATED;
        // error code is not included in error_reporting
        if (!$isDeprecationNotice && 0 === (error_reporting() & $level)) {
            return true;
        }
        if (filter_var(ini_get('xdebug.scream'), FILTER_VALIDATE_BOOLEAN)) {
            $message .= "\n\nWarning: You have xdebug.scream enabled, the warning above may be" . "\na legitimately suppressed error that you were not supposed to see.";
        }
        if (!$isDeprecationNotice) {
            throw new \ErrorException($message, 0, $level, $file, $line);
        }
        if (self::$io !== null) {
            self::$io->writeError('<warning>Deprecation Notice: ' . $message . ' in ' . $file . ':' . $line . '</warning>');
            if (self::$io->isVerbose()) {
                self::$io->writeError('<warning>Stack trace:</warning>');
                self::$io->writeError(array_filter(array_map(static function ($a) : ?string {
                    if (isset($a['line'], $a['file'])) {
                        return '<warning> ' . $a['file'] . ':' . $a['line'] . '</warning>';
                    }
                    return null;
                }, array_slice(debug_backtrace(), 2)), function (?string $line) {
                    return $line !== null;
                }));
            }
        }
        return true;
    }
    
    /**
     * Register error handler.
     */
    public static function register(?IOInterface $io = null) : void {
        set_error_handler([
            __CLASS__,
            'handle',
        ]);
        error_reporting(E_ALL);
        self::$io = $io;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ErrorHandler::$io private static property @var ?IOInterface
ErrorHandler::handle public static function Error handler
ErrorHandler::register public static function Register error handler.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal