-
Notifications
You must be signed in to change notification settings - Fork 23
Description
The check for type declarations has an handy exceptions that don't require type declaration when the callback is used for a WordPress hook.
It works when a closure is directly added to an hook, e.g.:
add_action('init', function () { /* ... */ });
or when the @wp-hook
annotation is used:
/**
* @wp-hook init
*/
function fooBar() { /* ... */ }
However, there are two issues currently:
- Closures are not recognized when they are static
- Class methods are not recognized if not public
Regarding second point, it is true that only public methods can be used directly in a hook, but it is quite common to have a closure that acts as a proxy to a private method, something like:
add_action('init', function ($args) { $this->doSomething($args) });
This allows to use separate methods, without exposing them as public. However, in the example above the closure will not be required to have type, but the doSomething
method will be required, even if the @wp-hook
annotation is used, so only chance is to either make it public (at that point having the closure does not make sense anymore) or manually excluding the type declaration check.