Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 5, 2025

⚠️ This PR needs for PR #1806 to be merged first. It relies on functionality supported since PHPCSUtils 1.1.0. ⚠️

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

. 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:

Related to #1731

PHP 8.4 | NewFunctionCallTrailingComma: handle trailing comma's for exit/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:

Related to #1731

PHP 8.4 | ✨ New PHPCompatibility.ParameterValues.NewExitAsFunctionCall 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:

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.

@jrfnl jrfnl added this to the 10.0.0 milestone Jul 5, 2025
@jrfnl jrfnl requested a review from wimg July 5, 2025 22:29
Base automatically changed from feature/composer-update-for-phpcsutils-1.1.0 to develop July 6, 2025 13:28
@jrfnl
Copy link
Member Author

jrfnl commented Jul 6, 2025

Rebased without changes after the merge of #1806 and marked as "ready for review".

@jrfnl jrfnl marked this pull request as ready for review July 6, 2025 13:34
@jrfnl jrfnl force-pushed the php-8.4/exit-as-function-call branch from 4520a6c to 57c5439 Compare July 6, 2025 13:35
@jrfnl jrfnl marked this pull request as draft August 3, 2025 01:01
@jrfnl
Copy link
Member Author

jrfnl commented Aug 3, 2025

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.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 5, 2025

I've updated the test code in this PR to include fully qualified calls to exit/die in light of the changed tokenization in PHPCS 3.13.3 (and 4.0.0).

I've also added a new error to the NewExitAsFunctionCall to flag fully qualified use of exit/die.

Rebased after the merge of #1900. 🤞🏻 I expect the build to pass now.

@jrfnl jrfnl force-pushed the php-8.4/exit-as-function-call branch from 711a1ed to b7408bc Compare September 5, 2025 18:18
…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_
@jrfnl jrfnl force-pushed the php-8.4/exit-as-function-call branch from b7408bc to c9dd0a1 Compare September 5, 2025 22:40
@wimg wimg merged commit 133dea0 into develop Sep 8, 2025
48 checks passed
@wimg wimg deleted the php-8.4/exit-as-function-call branch September 8, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants