PHP 8.5 | TypeCasts/RemovedTypeCasts: detect newly deprecated type casts (RFC) #1941
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.
This commit adds detection of these newly deprecated type casts to the existing
RemovedTypeCastssniff.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 theT_DOUBLE_CASTtoken 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_castDeprecatedRemovedfor the(real)cast andt_double_castDeprecatedfor the(double)cast, though that would also becomet_double_castDeprecatedRemovedonce 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.
realDeprecatedRemovedvsdoubleDeprecated.👉 This change in error codes will need to be annotated in the changelog as a breaking change!
Refs:
Related to #1849