static_lambda.rst 613 B

12345678910111213141516171819202122232425262728293031323334353637
  1. ======================
  2. Rule ``static_lambda``
  3. ======================
  4. Lambdas not (indirectly) referencing ``$this`` must be declared ``static``.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when using ``->bindTo`` on lambdas without referencing to ``$this``.
  10. Examples
  11. --------
  12. Example #1
  13. ~~~~~~~~~~
  14. .. code-block:: diff
  15. --- Original
  16. +++ New
  17. <?php
  18. -$a = function () use ($b)
  19. +$a = static function () use ($b)
  20. { echo $b;
  21. };
  22. Rule sets
  23. ---------
  24. The rule is part of the following rule set:
  25. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_