static_lambda.rst 456 B

12345678910111213141516171819202122232425
  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. <?php
  15. -$a = function () use ($b)
  16. +$a = static function () use ($b)
  17. { echo $b;
  18. };