hookphp icon indicating copy to clipboard operation
hookphp copied to clipboard

hookBefore, hookAfter and replace original method?

Open pwFoo opened this issue 5 years ago • 1 comments

Your example show how to modifiy the arguments before executing the original method ("hookBefore").

But would it possible to replace /stop the execution of the original method? Example from a cms I know.

// $event is the current object with all additional features of the cms like "global" variables, ...
$event->replace = true; // do not execute the original method after the hook finishes

Or "hookAfter" original method is executed to manipulate the output?

$event->return = $value; // manipulate or replace the return value of the original method

pwFoo avatar Dec 31 '19 20:12 pwFoo

Sorry, hookBefore / hookAfter works as should. Interesting part is how to replace a original method. If the hooks / methods executed in a loop the return value or a property could be checked to break / skip the loop?

pwFoo avatar Dec 31 '19 21:12 pwFoo