0 關注者

類別 yii\base\ErrorException

繼承yii\base\ErrorException » ErrorException
自版本起可用2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorException.php

ErrorException 代表一個 PHP 錯誤。

關於 ErrorException 的更多詳細資訊和使用方法,請參閱關於處理錯誤的指南文章

公共方法

隱藏繼承的方法

方法 描述 定義於
__construct() 建構例外。 yii\base\ErrorException
getName() yii\base\ErrorException
isFatalError() 返回錯誤是否為嚴重類型之一。 yii\base\ErrorException

常數

隱藏繼承的常數

常數 描述 定義於
E_HHVM_FATAL_ERROR 16777217 此常數代表 HHVM 引擎中的嚴重錯誤。 PHP Zend 運行時不會在嚴重錯誤時呼叫錯誤處理程序,HHVM 會,錯誤代碼為 16777217。我們將在 HHVM 上以稍微不同的方式處理嚴重錯誤。 yii\base\ErrorException

方法詳情

隱藏繼承的方法

__construct() public method

建構例外。

public void __construct ( $message '', $code 0, $severity 1, $filename __FILE__, $lineno __LINE__, $previous null )
$message 字串

[可選]

$code 整數

[可選]

$severity 整數

[可選]

$filename 字串

[可選]

$lineno 整數

[可選]

$previous Throwable|null

[可選]

                public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, $previous = null)
{
    parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
    if ($this->isXdebugStackAvailable()) {
        // Xdebug trace can't be modified and used directly with PHP 7
        // @see https://github.com/yiisoft/yii2/pull/11723
        $xdebugTrace = array_slice(array_reverse(xdebug_get_function_stack()), 1, -1);
        $trace = [];
        foreach ($xdebugTrace as $frame) {
            if (!isset($frame['function'])) {
                $frame['function'] = 'unknown';
            }
            // Xdebug < 2.1.1: https://bugs.xdebug.org/view.php?id=695
            if (!isset($frame['type']) || $frame['type'] === 'static') {
                $frame['type'] = '::';
            } elseif ($frame['type'] === 'dynamic') {
                $frame['type'] = '->';
            }
            // Xdebug has a different key name
            if (isset($frame['params']) && !isset($frame['args'])) {
                $frame['args'] = $frame['params'];
            }
            $trace[] = $frame;
        }
        $ref = new \ReflectionProperty('Exception', 'trace');
        $ref->setAccessible(true);
        $ref->setValue($this, $trace);
    }
}

            
getName() 公開方法

public string getName ( )
返回值 字串

此例外的使用者友善名稱

                public function getName()
{
    static $names = [
        E_COMPILE_ERROR => 'PHP Compile Error',
        E_COMPILE_WARNING => 'PHP Compile Warning',
        E_CORE_ERROR => 'PHP Core Error',
        E_CORE_WARNING => 'PHP Core Warning',
        E_DEPRECATED => 'PHP Deprecated Warning',
        E_ERROR => 'PHP Fatal Error',
        E_NOTICE => 'PHP Notice',
        E_PARSE => 'PHP Parse Error',
        E_RECOVERABLE_ERROR => 'PHP Recoverable Error',
        E_STRICT => 'PHP Strict Warning',
        E_USER_DEPRECATED => 'PHP User Deprecated Warning',
        E_USER_ERROR => 'PHP User Error',
        E_USER_NOTICE => 'PHP User Notice',
        E_USER_WARNING => 'PHP User Warning',
        E_WARNING => 'PHP Warning',
        self::E_HHVM_FATAL_ERROR => 'HHVM Fatal Error',
    ];
    return isset($names[$this->getCode()]) ? $names[$this->getCode()] : 'Error';
}

            
isFatalError() 公開靜態方法

返回錯誤是否為嚴重類型之一。

public static boolean isFatalError ( $error )
$error array

從 error_get_last() 取得的錯誤

返回值 boolean

如果錯誤是致命類型之一

                public static function isFatalError($error)
{
    return isset($error['type']) && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, self::E_HHVM_FATAL_ERROR]);
}