PHP 8.4 | Handle "Exit as function call" in various sniffs#1807
Merged
PHP 8.4 | Handle "Exit as function call" in various sniffs#1807
Conversation
58 tasks
Base automatically changed from
feature/composer-update-for-phpcsutils-1.1.0
to
develop
July 6, 2025 13:28
Member
Author
|
Rebased without changes after the merge of #1806 and marked as "ready for review". |
4520a6c to
57c5439
Compare
Member
Author
|
Temporarily moving this to draft as I found another situation which needs to be handled (exit/die as fully qualified function) and will (most likely) mean that all commits related to this PHP change need to be updated. |
57c5439 to
40dccb5
Compare
40dccb5 to
711a1ed
Compare
Member
Author
|
I've updated the test code in this PR to include fully qualified calls to I've also added a new error to the Rebased after the merge of #1900. 🤞🏻 I expect the build to pass now. |
711a1ed to
b7408bc
Compare
…able > . 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 detection of the use of `exit()`/`die()` as a first class callable to the `NewFirstClassCallables` sniff. Includes tests. Includes updated 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 Related to 1731
…xit/die > . 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 detection of the use of trailing comma's in `exit()`/`die()` to the `NewFunctionCallTrailingComma` sniff. Includes tests. 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 Related to 1731
…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_
b7408bc to
c9dd0a1
Compare
wimg
approved these changes
Sep 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #1806 also contains one commit - 297d6b1 - which, by rights, should be part of this PR.
PHP 8.4 | NewFirstClassCallables: handle exit/die as first class callable
This commit adds detection of the use of
exit()/die()as a first class callable to theNewFirstClassCallablessniff.Includes tests.
Includes updated documentation.
Refs:
Related to #1731
PHP 8.4 | NewFunctionCallTrailingComma: handle trailing comma's for exit/die
This commit adds detection of the use of trailing comma's in
exit()/die()to theNewFunctionCallTrailingCommasniff.Includes tests.
Refs:
Related to #1731
PHP 8.4 | ✨ New
PHPCompatibility.ParameterValues.NewExitAsFunctionCallsniffThis commit adds a new sniff which:
exit/dieas fully qualified function calls, which is not allowed prior to 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:
Related to #1731
PHP 8.4 | FunctionUse/NewNamedParameters: update tests to safeguard handling FQN exit/die
... which is allowed since PHP 8.4... sigh
Follow up to #1806 which already updated the sniff itself.