phpstan-wordpress icon indicating copy to clipboard operation
phpstan-wordpress copied to clipboard

Spot non-existent method/function in remove_action()

Open szepeviktor opened this issue 2 years ago • 3 comments

remove_action('wp_enqueue_scripts', [$theme, 'wp_common_block_scripts_and_styles']);

This triggered no error on level 5. How could that be?

ps. wp_common_block_scripts_and_styles is a global function from core

szepeviktor avatar Aug 07 '23 10:08 szepeviktor

This is expected behaviour. The $callback parameter doesn't have to be valid.

 * @param callable|string|array $callback  The name of the function which should be removed.
 *                                         This function can be called unconditionally to speculatively remove
 *                                         a callback that may or may not exist.

johnbillion avatar Aug 07 '23 10:08 johnbillion

Thank you, John.

(For extraterrestrial aliens 👽) could you add something like HookCallbackRule that checks for callback existence in hooking function? And has a parameter that activates it, so it is off by default (for earthlings).

szepeviktor avatar Aug 07 '23 10:08 szepeviktor

I'd rather not 🤣

johnbillion avatar Aug 07 '23 12:08 johnbillion