strict_param.rst 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. =====================
  2. Rule ``strict_param``
  3. =====================
  4. Functions should be used with ``$strict`` param set to ``true``.
  5. Description
  6. -----------
  7. The functions "array_keys", "array_search", "base64_decode", "in_array" and
  8. "mb_detect_encoding" should be used with $strict param.
  9. Warning
  10. -------
  11. Using this rule is risky
  12. ~~~~~~~~~~~~~~~~~~~~~~~~
  13. Risky when the fixed function is overridden or if the code relies on non-strict
  14. usage.
  15. Examples
  16. --------
  17. Example #1
  18. ~~~~~~~~~~
  19. .. code-block:: diff
  20. --- Original
  21. +++ New
  22. <?php
  23. $a = array_keys($b);
  24. -$a = array_search($b, $c);
  25. -$a = base64_decode($b);
  26. -$a = in_array($b, $c);
  27. -$a = mb_detect_encoding($b, $c);
  28. +$a = array_search($b, $c, true);
  29. +$a = base64_decode($b, true);
  30. +$a = in_array($b, $c, true);
  31. +$a = mb_detect_encoding($b, $c, true);
  32. Rule sets
  33. ---------
  34. The rule is part of the following rule set:
  35. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  36. References
  37. ----------
  38. - Fixer class: `PhpCsFixer\\Fixer\\Strict\\StrictParamFixer <./../../../src/Fixer/Strict/StrictParamFixer.php>`_
  39. - Test class: `PhpCsFixer\\Tests\\Fixer\\Strict\\StrictParamFixerTest <./../../../tests/Fixer/Strict/StrictParamFixerTest.php>`_
  40. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.