Is your feature request related to a problem? Please describe.
When we register hooks, no checks are done to control the existence of related functions expected by Hook class.
So we can expect a hook to be hooked (lol) while the function is not here (or wrongly named).
Describe the solution you'd like
Something like an exception with the following message:
"WrongHookRegistrationException: hook with the name %hookName% has been registered, but the following function %functionName% is not defined in the Module class %className%.
Describe alternatives you've considered
Be allowed to set the function name while registering the hook or be allowed to pass a callable.
$this->registerHook('foo', function ($hookParams) {
/// whatever ...
});
Additional context
I'm sad I want to cry a river ;)
Ping @PrestaShop/prestashop-core-developers
@mickaelandrieu This would require us to use Reflection on the Module to make sure the right function exists 馃 when registerHook(...) is used, right ?
@matks It can be done after this if / elseif: https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Hook.php#L896
The function isHookCallableOn a module is already available.
I'm pretty sure this would be a breaking change :)
@kpodemski To make it less violent, we could only allow this in DEBUG mode, or convert it to a notice error message ?
@matks notice should be ok 馃憤
Most helpful comment
@kpodemski To make it less violent, we could only allow this in DEBUG mode, or convert it to a notice error message ?