Understanding PHP Throwable, Error, and Exception Classes in PHP 8.3

This article explains the Throwable interface, the Error and Exception base classes, their properties and methods, provides a hierarchical overview of PHP exception types, and outlines the upcoming PHP 8.3 release schedule and repository details.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Understanding PHP Throwable, Error, and Exception Classes in PHP 8.3

Error

Overview

Error is the base class for all internal PHP error classes.

Class Summary

<?php
class Error implements Throwable {
    /* properties */
    protected string $message = "";
    private string $string = "";
    protected int $code;
    protected string $file = "";
    protected int $line;
    private array $trace = [];
    private ?Throwable $previous = null;

    /* methods */
    public __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
    final public getMessage(): string
    final public getPrevious(): ?Throwable
    final public getCode(): int
    final public getFile(): string
    final public getLine(): int
    final public getTrace(): array
    final public getTraceAsString(): string
    public __toString(): string
    private __clone(): void
}

Method Index

Error::__construct

— initialize error object Error::getMessage — retrieve error message Error::getPrevious — return previous Throwable Error::getCode — get error code Error::getFile — get file where error occurred Error::getLine — get line number of error Error::getTrace — obtain stack trace Error::getTraceAsString — stack trace as string Error::__toString — string representation of error Error::__clone — clone error object

Exception

Overview

Exception is the base class for all user‑level exceptions.

Class Summary

<?php
class Exception implements Throwable {
    /* properties */
    protected string $message = "";
    private string $string = "";
    protected int $code;
    protected string $file = "";
    protected int $line;
    private array $trace = [];
    private ?Throwable $previous = null;

    /* methods */
    public __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
    final public getMessage(): string
    final public getPrevious(): ?Throwable
    final public getCode(): int
    final public getFile(): string
    final public getLine(): int
    final public getTrace(): array
    final public getTraceAsString(): string
    public __toString(): string
    private __clone(): void
}

Method Index

Exception::__construct

— exception constructor Exception::getMessage — retrieve exception message Exception::getPrevious — return previous Throwable Exception::getCode — get exception code Exception::getFile — file where exception was created Exception::getLine — line number in file where exception was created Exception::getTrace — obtain exception trace information Exception::getTraceAsString — trace as string Exception::__toString — convert exception to string Exception::__clone — clone exception

Exception Hierarchy Overview

A quick chart summarises the exception tree used in PHP versions.

Throwable
  ├── Error
  │     ├── ArithmeticError
  │     │       └── DivisionByZeroError
  │     ├── AssertionError
  │     ├── CompileError
  │     │       └── ParseError
  │     ├── TypeError
  │     │       └── ArgumentCountError
  │     ├── ValueError
  │     ├── UnhandledMatchError
  │     ├── FiberError
  │     └── Random\RandomError
  │           └── BrokenRandomEngineError
  │     └── DateError
  │           ├── DateObjectError
  │           └── DateRangeError
  └── Exception
        ├── ClosedGeneratorException
        ├── DOMException
        ├── ErrorException
        ├── IntlException
        ├── JsonException
        ├── LogicException
        │     ├── BadFunctionCallException
        │     │     └── BadMethodCallException
        │     ├── DomainException
        │     ├── InvalidArgumentException
        │     ├── LengthException
        │     └── OutOfRangeException
        ├── PharException
        ├── ReflectionException
        ├── RuntimeException
        │     ├── OutOfBoundsException
        │     ├── OverflowException
        │     ├── PDOException
        │     ├── RangeException
        │     ├── UnderflowException
        │     └── UnexpectedValueException
        ├── SodiumException
        ├── FiberExit
        ├── Random\RandomException
        └── DateException
              ├── DateInvalidTimeZoneException
              ├── DateInvalidOperationException
              ├── DateMalformedStringException
              ├── DateMalformedIntervalStringException
              └── DateMalformedPeriodStringException

PHP 8.3 Release Information

PHP 8.3 is the first release candidate for the upcoming PHP version and is now available for testing.

The first generally available PHP version is scheduled for release on November 23 this year; the RC indicates that all changes for PHP 8.3 have been implemented, leaving only polishing and bug fixes.

Before the final 8.3.0 release, five more release candidates will be issued, each two weeks apart.

PHP 8.3.0RC1 is tagged in the php-src repository, and a dedicated PHP-8.3 branch will be used for further 8.3 development, while the main branch now targets the upcoming PHP 8.4 release.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendExceptionphp8.3error-handlingErrorthrowable
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.