Skip to content

Exit in register_shutdown_function overwrites exit code since PHP8.4 #22123

@PrinsFrank

Description

@PrinsFrank

Description

The following code:

<?php declare(strict_types=1);

register_shutdown_function(static function () {
    exit; // prevent further shutdown handlers from being called
});

exit(1);

https://3v4l.org/C9oKE#v

Results in exit code 0 since PHP8.4, while it returned the original exit code 1 in previous versions.

According to the documentation, this is should be a valid way to stop shutdown_function propagation:

If you call exit() within one registered shutdown function, processing will stop completely and no other registered shutdown functions will be called.

This was spotted in #15796 with a potential fix in #19445, but both don't fix the breaking change. It's also not mentioned in the upgrade guide from PHP8.3 to PHP8.4. Was this intended to be a breaking change? Should this be documented somewhere?

PHP Version

8.4.1 - 8.4.18, 8.5.0 - 8.5.3 (from above sample from 3v4l.org)

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions