PHP 8.4 | Handle "Exit as function call" in various sniffs by jrfnl · Pull Request #1807 · PHPCompatibility/PHPCompatibility

@jrfnl jrfnl mentioned this pull request

Jul 5, 2025

58 tasks

Base automatically changed from feature/composer-update-for-phpcsutils-1.1.0 to develop

July 6, 2025 13:28

@jrfnl jrfnl marked this pull request as ready for review

July 6, 2025 13:34

@jrfnl jrfnl marked this pull request as draft

August 3, 2025 01:01

@jrfnl jrfnl marked this pull request as ready for review

September 5, 2025 14:28

@jrfnl

@jrfnl

…ll` sniff

> . The exit (and die) language constructs now behave more like a function.
>   They can be passed liked callables, are affected by the strict_types
>   declare statement, and now perform the usual type coercions instead of
>   casting any non-integer value to a string.
>   As such, passing invalid types to exit/die may now result in a TypeError
>   being thrown.
>   RFC: https://wiki.php.net/rfc/exit-as-function

This commit adds a new sniff which:
1. Will flag use of `exit`/`die` as fully qualified function calls, which is not allowed prior to PHP 8.4.
2. Tries to detect parameter values which will either be interpreted differently or will (likely) result in a TypeError on PHP 8.4.

Calls to `exit()`/`die()` for which the parameter type cannot be determined are silently ignored to prevent false positives.

Includes tests.
Includes documentation.

Refs:
* https://wiki.php.net/rfc/exit-as-function
* https://github.com/php/php-src/blob/8853cf3ae950a1658054f286117bc8f77f724f00/UPGRADING#L40-L46
* php/php-src 13486
* php/php-src@a79c70f
* php/php-src 15433
* php/php-src@4c5767f

Related to 1731
…andling FQN exit/die

... which is allowed since PHP 8.4... _sigh_

wimg

wimg approved these changes Sep 8, 2025

@wimg wimg deleted the php-8.4/exit-as-function-call branch

September 8, 2025 14:44

@jrfnl jrfnl mentioned this pull request

Oct 12, 2025

@jrfnl jrfnl mentioned this pull request

Nov 19, 2025