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

Consider making all closures static #126

Open
knutsp opened this issue Jun 7, 2024 · 0 comments
Open

Consider making all closures static #126

knutsp opened this issue Jun 7, 2024 · 0 comments

Comments

@knutsp
Copy link

knutsp commented Jun 7, 2024

From
add_filter('some_filter', function ($params...) { }
To:
add_filter('some_filter', static function ($params...) { }

Similar for add_action with closure.
In case the magic instance variable $this is not needed inside it.

This avoids the closures to bind to each instance, probably a bit less memory and maybe a bit faster, especially in frequently instantiated classes (I think).

Also consider using named functions in case it may be useful for other (site specific) plugins to completely remove the action or filter.

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