PHP 8.5 | TypeCasts/RemovedTypeCasts: detect newly deprecated type casts (RFC) by jrfnl · Pull Request #1941 · PHPCompatibility/PHPCompatibility
…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
mentioned this pull request
70 tasks
wimg approved these changes Oct 27, 2025
wimg
deleted the
php-8.5/removedtypecasts-handle-new-deprecations
branch
jrfnl
mentioned this pull request
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