Skip to content

Add the 13 SPL exception classes (RuntimeException, LogicException, …)#245

Merged
alganet merged 1 commit into
mainfrom
feature/spl-exceptions
Jun 15, 2026
Merged

Add the 13 SPL exception classes (RuntimeException, LogicException, …)#245
alganet merged 1 commit into
mainfrom
feature/spl-exceptions

Conversation

@alganet

@alganet alganet commented Jun 15, 2026

Copy link
Copy Markdown
Owner

The SPL exception hierarchy was undeclared — class_exists("RuntimeException") returned false, so any framework or library code that throws or catches these (extremely common) types died with "Call to undefined class".

Added all 13 as embedded PHP source in the PH7_BUILTIN_LIB macro (vm.c, after ErrorException), following the existing class X extends Error { } template — no C required. They use PHP's exact two-root hierarchy so catch / instanceof / get_parent_class match PHP:
LogicException, RuntimeException extends Exception
BadFunctionCallException, DomainException, InvalidArgumentException,
LengthException, OutOfRangeException extends LogicException
BadMethodCallException extends BadFunctionCallException
OutOfBoundsException, OverflowException, RangeException, UnderflowException,
UnexpectedValueException extends RuntimeException

Each is an empty body inheriting Exception's constructor and getMessage/getCode/getPrevious/... Declaration order places the two roots before their subclasses so the compile-time parent resolution succeeds. Declared-class count: 14 -> 27.

Byte-for-byte parity with PHP 8.5.7 (catch-by-base, instanceof chains, get_parent_class, inherited ctor/getMessage/getCode all match). Regression: lang/spl_exception_{class_exists,hierarchy,instanceof,catch_by_base}.phpt (pass under both phl and real php). make test / test-compat green.

The SPL exception hierarchy was undeclared — class_exists("RuntimeException")
returned false, so any framework or library code that throws or catches these
(extremely common) types died with "Call to undefined class".

Added all 13 as embedded PHP source in the PH7_BUILTIN_LIB macro (vm.c, after
ErrorException), following the existing `class X extends Error { }` template — no
C required. They use PHP's exact two-root hierarchy so catch / instanceof /
get_parent_class match PHP:
  LogicException, RuntimeException        extends Exception
  BadFunctionCallException, DomainException, InvalidArgumentException,
  LengthException, OutOfRangeException    extends LogicException
  BadMethodCallException                  extends BadFunctionCallException
  OutOfBoundsException, OverflowException, RangeException, UnderflowException,
  UnexpectedValueException                extends RuntimeException

Each is an empty body inheriting Exception's constructor and
getMessage/getCode/getPrevious/... Declaration order places the two roots
before their subclasses so the compile-time parent resolution succeeds.
Declared-class count: 14 -> 27.

Byte-for-byte parity with PHP 8.5.7 (catch-by-base, instanceof chains,
get_parent_class, inherited ctor/getMessage/getCode all match). Regression:
lang/spl_exception_{class_exists,hierarchy,instanceof,catch_by_base}.phpt
(pass under both phl and real php). make test / test-compat green.
@alganet alganet merged commit 8000c75 into main Jun 15, 2026
20 checks passed
@github-actions

Copy link
Copy Markdown

Coverage

Total Rate Hit/Total
Lines 79.03% 32097/40612
Functions 95.40% 1493/1565

Details: https://github.com/alganet/PHL/actions/runs/27577744001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant