string_length_to_empty.rst 757 B

123456789101112131415161718192021222324252627282930313233343536
  1. ===============================
  2. Rule ``string_length_to_empty``
  3. ===============================
  4. String tests for empty must be done against ``''``, not with ``strlen``.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when ``strlen`` is overridden, when called using a ``stringable`` object,
  10. also no longer triggers warning when called using non-string(able).
  11. Examples
  12. --------
  13. Example #1
  14. ~~~~~~~~~~
  15. .. code-block:: diff
  16. --- Original
  17. +++ New
  18. -<?php $a = 0 === strlen($b) || \STRLEN($c) < 1;
  19. +<?php $a = '' === $b || $c === '';
  20. Rule sets
  21. ---------
  22. The rule is part of the following rule sets:
  23. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  24. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_