This is an old revision of the document!

PHP RFC: StackFrame class


The debug_backtrace() function currently returns stack trace frames as an array of arrays with information about the file, line, class, type, object, args and function name as keys. This RFC proposes to add a debug_backtrace() alternative which returns an array of objects instead. This reduces memory usage and makes code operating on frames more readable.


Introduce new StackFrame with static method getTrace() and optionally replace Exception class trace with array of StackFrame objects.

StackFrame class provides properties and methods which mirrors information from debug_backtrace():

final class StackFrame implements ArrayAccess
    public readonly string $file;
    public readonly int $line;
    public readonly ?string $function;
    public readonly ?string $class;
    public readonly ?object $object;
    public readonly array $args;
    public static function getTrace(): array {}
    public function getFile(): string {}
    public function getLine(): int {}
    public function getFunction(): ?string {}
    public function getClass(): ?string {}
    public function getObject(): ?object {}
    public function getType(): ?string {}
    public function getArgs(): array {}

Backward Incompatible Changes

If vote decides about changing Exception trace with array of StackTrace objects then Exception::getTrace() method will no longer be a mutable array of arrays with simple keys. Although a StackFrame implements ArrayAccess interface and allow to read all keys in BC manner manipulation on frames will no longer be possible.

Proposed PHP Version(s)

Next PHP 8.0

RFC Impact



To Existing Extensions


To Opcache


New Constants

Not yet.

Proposed Voting Choices

As this is a language in exception handling mechanism it requires 2/3 accepted. The vote will be a simple Yes/No for StackFrame inclusion and second vote a simple Yes/No for exception trace replacement.



rfc/stack-frame-class.1594152440.txt.gz · Last modified: 2020/07/07 20:07 by brzuchal