Skip to content

Type cast rules in handbook incomplete - missing (double), (unset), (binary) documentation #154

@rodrigoprimo

Description

@rodrigoprimo

While reviewing PR #2591 which adds documentation for the WordPress.PHP.TypeCasts sniff, I noticed that https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#space-usage doesn't fully document all the rules that the WordPress.PHP.TypeCasts sniff enforces in the paragraph about type casts.

The handbook currently documents:

  • Type casts must be lowercase (enforced by another sniff).
  • Use (int) not (integer).
  • Use (bool) not (boolean).
  • Use (float) not (real).

But the WordPress.PHP.TypeCasts sniff also enforces the following rules:

  • Use (float) instead of (double).
  • (unset) is forbidden.
  • (binary) and b"string" prefix are discouraged.

When the sniff was introduced in 2018 via PR WordPress/WordPress-Coding-Standards#1483, I believe the intention was to mention (unset) and (binary) in the handbook (see WordPress/WordPress-Coding-Standards#1481 (comment) and WordPress/WordPress-Coding-Standards#1481 (comment)), but it seems that never happened or at least I was not able to find it searching the history of https://github.com/WordPress/wpcs-docs/blame/master/wordpress-coding-standards/php.md.

(double) is not mentioned in the issue discussion, but to me, since 4361cec added a explicit mention to (real), I think (double) should be mentioned as well.

Should the handbook be updated or is there a reason that I'm missing not to update it? Also, please let me know if this is not the correct repository to ask this question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions