static_lambda.rst 475 B

1234567891011121314151617181920212223242526
  1. ======================
  2. Rule ``static_lambda``
  3. ======================
  4. Lambdas not (indirect) referencing ``$this`` must be declared ``static``.
  5. .. warning:: Using this rule is risky.
  6. Risky when using ``->bindTo`` on lambdas without referencing to ``$this``.
  7. Examples
  8. --------
  9. Example #1
  10. ~~~~~~~~~~
  11. .. code-block:: diff
  12. --- Original
  13. +++ New
  14. @@ -1,4 +1,4 @@
  15. <?php
  16. -$a = function () use ($b)
  17. +$a = static function () use ($b)
  18. { echo $b;
  19. };