Docs: Add documentation for WordPress.PHP.TypeCasts
Related to #1722
This PR adds a new documentation file:
WordPress/Docs/PHP/TypeCastsStandard.xml
What it covers
Documents the rule enforced by the WordPress.PHP.TypeCasts sniff:
- Normalizes legacy float casts (
(double),(real)) to(float).
Notes
Other type-cast related rules in the WordPress standard are enforced by separate sniffs:
- Short form keywords (
(int),(bool),(string)): PSR12.Keywords.ShortFormTypeKeywords - No spaces inside parentheses: Squiz.WhiteSpace.CastSpacing
- Exactly one space after the cast: Generic.Formatting.SpaceAfterCast
I just realized something else. From php.net (https://www.php.net/manual/en/language.types.type-juggling.php):
Caution The (binary) cast and b prefix exists for forward support. Currently (binary) and (string) are identical, however this may change and should not be relied upon.
Since the manual says that there is no guarantee that (binary) and (string) will continue to be identical, I guess we should not recommend it in the documentation. Instead maybe the documentation should say that using (binary) is not recommended without providing an alternative? That may be the reason the sniff message does not recommend using (string).
Since the manual says that there is no guarantee that (binary) and (string) will continue to be identical, I guess we should not recommend it in the documentation. Instead maybe the documentation should say that using (binary) is not recommended without providing an alternative? That may be the reason the sniff message does not recommend using (string).
Just so you know: the (binary) cast is deprecated as of PHP 8.5 and will be removed in PHP 9.0. The suggested replacement is using (string). See: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names
Thanks for your input, @jrfnl. In that case, I think that @brentwilson-clariio can ignore my last comment and the documentation can mention that (string) should be used instead of (binary).
@brentwilson-clariio , I was just wondering if you'll have a chance to finish this off in the near future. It would be great if this PR could be included in the next WPCS release.
If you haven't got time or lost interest, please let us know, and we'll see if we can find someone to take over. Thanks!
@rodrigoprimo Let me see if I can circle back to this in the next week or two to get it finished up.