2024 日本 PHP 研討會

錯誤

(PHP 7, PHP 8)

簡介

Error 是所有 PHP 內部錯誤的基底類別。

類別概要

class Error implements Throwable {
/* 屬性 */
受保護的 字串 $message = "";
私有的 字串 $string = "";
受保護的 整數 $code;
受保護的 字串 $file = "";
受保護的 整數 $line;
私有的 陣列 $trace = [];
私有的 ?Throwable $previous = null;
/* 方法 */
公開的 __construct(字串 $message = "", 整數 $code = 0, ?Throwable $previous = null)
最終 公開的 取得訊息(): 字串
最終 公開的 取得前一個(): ?Throwable
最終 公開的 取得代碼(): 整數
最終 公開的 取得檔案(): 字串
最終 公開的 取得行數(): 整數
最終 公開的 取得追蹤(): 陣列
最終 公開的 取得追蹤字串(): 字串
公開 __toString(): 字串
私有 __clone():
}

屬性

message

錯誤訊息

code

錯誤碼

file

發生錯誤的檔案名稱

line

發生錯誤的行數

previous

先前拋出的例外

string

堆疊追蹤的字串表示

trace

堆疊追蹤,以陣列形式呈現

目錄

新增註記

使用者貢獻的註記 3 則註記

51
whysteepy at gmail dot com
6 年前
7.2.0 版的 Throwable 和 Exception 樹狀結構列表

錯誤
ArithmeticError
DivisionByZeroError
AssertionError
ParseError
TypeError
ArgumentCountError
Exception
ClosedGeneratorException
DOMException
ErrorException
IntlException
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
PharException
ReflectionException
RuntimeException
OutOfBoundsException
OverflowException
PDOException
RangeException
UnderflowException
UnexpectedValueException
SodiumException

在以下連結中找到腳本和輸出
https://gist.github.com/mlocati/249f07b074a0de339d4d1ca980848e6a
https://3v4l.org/sDMsv

發佈於此 https://php.dev.org.tw/manual/en/class.throwable.php
21
dams at php dot net
2 年前
8.1.0 版的 Throwable 和 Exception 樹狀結構列表

錯誤
ArithmeticError
DivisionByZeroError
AssertionError
CompileError
ParseError
FiberError
TypeError
ArgumentCountError
UnhandledMatchError
ValueError
Exception
ClosedGeneratorException
DOMException
ErrorException
IntlException
JsonException
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
PharException
ReflectionException
RuntimeException
OutOfBoundsException
OverflowException
PDOException
RangeException
UnderflowException
UnexpectedValueException
SodiumException

在以下連結中找到腳本和輸出
https://gist.github.com/mlocati/249f07b074a0de339d4d1ca980848e6a
https://3v4l.org/f8Boe

最初由 whysteepy at gmail dot com 發佈,適用於 PHP 7.2.0,基於 gist
1
JustinasMalkas
8 年前
如果您在升級 PHP 後遇到錯誤訊息「PHP Fatal error: Cannot declare class error, because the name is already in use ...」,您必須重新命名您的「error」類別。
因為從 PHP 7 開始,類別名稱「Error」已被預先定義並於內部使用。
To Top