Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SlevomatCodingStandard.Functions.StaticClosure: provide setting to toggle for arrow functions or traditional closures #1711

Open
montchr opened this issue Nov 13, 2024 · 0 comments

Comments

@montchr
Copy link

montchr commented Nov 13, 2024

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

Personally, I would prefer to avoid the addition of static for arrow functions,
as it seems they are, by design, intended to provide a concise syntax without
static. Since I don't particularly care about static for traditional closures,
I am fine with just removing this sniff from my configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant