PHP: How to realize event handler?

SolomonNoel

New Member
I want to add custom event handler to object's method.I've got a class with method.\[code\]class Post { public function Add($title) { // beforeAdd event should be called here echo 'Post "' . $title . '" added.'; return; }}\[/code\]I want to add an event to method \[code\]Add\[/code\] and pass method's argument(s) to the event handler.\[code\]function AddEventHandler($event, $handler){ // What should this function do?}$handler = function($title){ return strtoupper($title);}AddEventHandler('beforeAdd', $handler);\[/code\]Is it possible to do something like this? Hope my question is clear.
 
Back
Top