uuid icon indicating copy to clipboard operation
uuid copied to clipboard

Static lambda

Open MathiasReker opened this issue 1 year ago • 2 comments

Description

Lambdas not (indirect) referencing $this must be declared static.

Motivation and context

How has this been tested?

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

PR checklist

  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING.md document.
  • [ ] I have added tests to cover my changes.

MathiasReker avatar Jul 04 '22 16:07 MathiasReker

Is this a coding standard or best practice that's defined somewhere?

ramsey avatar Jul 05 '22 05:07 ramsey

It is best practice as these lambdas can then not be bound to an object.

For reference, see https://www.designcise.com/web/tutorial/what-are-static-anonymous-functions-in-php

MathiasReker avatar Jul 07 '22 12:07 MathiasReker