Skip to content

Add the PHP 8.5 trace key to error_get_last() - #6470

Merged
ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
janedbal:error-get-last-php85-trace
Sep 17, 2026
Merged

ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
janedbal:error-get-last-php85-trace

Conversation

@janedbal

Copy link
Copy Markdown
Contributor

PHP 8.5 added the fatal_error_backtraces INI setting, which is enabled by default. PHP then collects a backtrace for fatal errors, and error_get_last() returns it under the trace key:

register_shutdown_function(static function (): void {
    // PHP 8.5: ["type", "message", "file", "line", "trace"]
    // PHP 8.4: ["type", "message", "file", "line"]
    var_dump(array_keys(error_get_last()));
});

The RFC only populates the key for fatal errors, and only in code that runs after shutdown, so the key is optional. The frame shape is the one debug_backtrace() already uses in functionMap.php.

Real-world impact: reading the new key currently reports Offset 'trace' ... does not exist, and because the value then narrows to null, every guard below it turns into Strict comparison ... will always evaluate to true and Unreachable statement. That makes the error unsuppressable in practice — an ignore silences the offset error but leaves the dead-code errors behind.

Follows the session_get_cookie_params() change in #6004, which added the PHP 8.5 partitioned key the same way.

PHP 8.5 adds the `fatal_error_backtraces` INI setting, which is enabled
by default. PHP then collects a backtrace for fatal errors and
`error_get_last()` returns it under the `trace` key.

The key is only present for fatal errors, and only in code that runs
after shutdown, so it is optional. The frame shape matches the one
`debug_backtrace()` already uses.

Co-Authored-By: Claude Code
@ondrejmirtes
ondrejmirtes merged commit 2faa295 into phpstan:2.2.x Sep 17, 2026
854 of 885 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you!

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.

2 participants