szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
262 stars 26 forks source link

Spot non-existent method/function in remove_action() #197

Open szepeviktor opened 1 year ago

szepeviktor commented 1 year ago
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

johnbillion commented 1 year ago

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.
szepeviktor commented 1 year ago

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).

johnbillion commented 1 year ago

I'd rather not 🤣