Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 25, 2025

. Non-canonical cast names (boolean), (integer), (double), and (binary) have
been deprecated, use (bool), (int), (float), and (string) respectively.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names

This commit adds detection of these newly deprecated type casts to the existing RemovedTypeCasts sniff.

Note: as a number of "cast" tokens cover multiple type casts, some of which are deprecated, some which are not, the setup of the sniff needed to change to be focussed on the text between the parentheses, not on the token type.

This also left me with a conundrum about the error codes. The pre-existing error codes were token type based, i.e.: PHPCompatibility.TypeCasts.RemovedTypeCasts.t_double_castDeprecatedRemoved. But the T_DOUBLE_CAST token covers three different type casts: (float), (double) and (real). The first (float) is still perfectly valid. The second is deprecated since PHP 8.5, while the third was deprecated in PHP 7.4 and removed in PHP 8.0.

So, leaving the error codes as they were, would create a confusing situation where, for now, we'd have t_double_castDeprecatedRemoved for the (real) cast and t_double_castDeprecated for the (double) cast, though that would also become t_double_castDeprecatedRemoved once support for the (double) cast is removed in PHP 9.0, which means we'd then have two different deprecations, which would be flagged with the same error code.

With this in mind and given that we are currently at a major release, I'm changing the error codes to be based on the contents of the cast, i.e. realDeprecatedRemoved vs doubleDeprecated.

👉 This change in error codes will need to be annotated in the changelog as a breaking change!

Refs:

Related to #1849

…sts (RFC)

> . Non-canonical cast names (boolean), (integer), (double), and (binary) have
>   been deprecated, use (bool), (int), (float), and (string) respectively.
>   RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names

This commit adds detection of these newly deprecated type casts to the existing `RemovedTypeCasts` sniff.

Note: as a number of "cast" tokens cover multiple type casts, some of which are deprecated, some which are not, the setup of the sniff needed to change to be focussed on the text between the parentheses, not on the token type.

This also left me with a conundrum about the error codes.
The pre-existing error codes were token type based, i.e.: `PHPCompatibility.TypeCasts.RemovedTypeCasts.t_double_castDeprecatedRemoved`.
But the `T_DOUBLE_CAST` token covers three different type casts: `(float)`, `(double)` and `(real)`. The first `(float)` is still perfectly valid. The second is deprecated since PHP 8.5, while the third was deprecated in PHP 7.4 and removed in PHP 8.0.

So, leaving the error codes as they were, would create a confusing situation where, for now, we'd have `t_double_castDeprecatedRemoved` for the `(real)` cast and `t_double_castDeprecated` for the `(double)` cast, though that would also become `t_double_castDeprecatedRemoved` once support for the `(double)` cast is removed in PHP 9.0, which means we'd then have two different deprecations, which would be flagged with the same error code.

With this in mind and given that we are currently at a major release, I'm changing the error codes to be based on the contents of the cast, i.e. `realDeprecatedRemoved` vs `doubleDeprecated`.

:point_right: This change in error codes will need to be annotated in the changelog as a breaking change!

Refs:
* https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names
* https://github.com/php/php-src/blob/1570ce9f551f7dff3f51690e5c03b0f5ae0e159f/UPGRADING#L364-L366
* php/php-src 19372
* php/php-src@3bf21a0
* php/php-src 19438
* php/php-src@bc475ad

Related to 1849
@jrfnl jrfnl added this to the 10.0.0-alpha2 milestone Oct 25, 2025
@jrfnl jrfnl requested a review from wimg October 25, 2025 23:00
@wimg wimg merged commit ca403fc into develop Oct 27, 2025
143 of 168 checks passed
@wimg wimg deleted the php-8.5/removedtypecasts-handle-new-deprecations branch October 27, 2025 20:25
@github-actions github-actions bot removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Oct 27, 2025
@jrfnl jrfnl added the PHP: 8.5 label Nov 4, 2025
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