Skip to content

Commit

Permalink
fix: remove requirement for static closures
Browse files Browse the repository at this point in the history
`SlevomatCodingStandard.Functions.StaticClosure` does not provide a setting to
toggle this sniff for only arrow functions or traditional `function` closure
syntax.

While declaring traditional closures static *might* be a best practice, the PHP
RFC introducing the arrow function implementation implies that declaring
`static` arrow functions is a micro-optimization in the majority of cases:

> For normal closures, [`$this` binding] can be prevented by prefixing them with
`static`. For the sake of completeness this is also supported for arrow
functions...

and:

> Static closures are rarely used: They're mainly used to prevent `$this`
cycles, which make GC behavior less predictable. Most code need not concern
itself with this.

<https://wiki.php.net/rfc/arrow_functions_v2#this_binding_and_static_arrow_functions>

I would prefer to avoid the addition of `static` for arrow functions, as they
are, by design, intended to provide a concise syntax *without* `static`.
  • Loading branch information
montchr committed Nov 13, 2024
1 parent cb879e9 commit 7497d79
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion Kleinweb/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ them to our own mu-plugin or standard library.
</rule>
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
<rule ref="SlevomatCodingStandard.Functions.UnusedParameter"/>
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
Expand Down

0 comments on commit 7497d79

Please sign in to comment.