static_lambda.rst 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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>`_
  26. References
  27. ----------
  28. - Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\StaticLambdaFixer <./../../../src/Fixer/FunctionNotation/StaticLambdaFixer.php>`_
  29. - Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\StaticLambdaFixerTest <./../../../tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php>`_
  30. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.