Simple PHP Hooking - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: Simple PHP Hooking (/showthread.php?tid=18759) |
Simple PHP Hooking - Sly - 05-14-2011 Yet another tutorial that I previously wrote. -- For those of us that love dynamic content, but not all the messy code that is required for it, hooks is my favorite way to go. An example of a hook class looks something like: PHP Code: <?php To add a hook in your PHP file, you would do something like this: PHP Code: <?php Then in your index file, you can run something like the following: PHP Code: <?php Do not forget that if you plan on running a hook more than once, you will need to clear the hook after you run it before adding more functions to run. Otherwise you're going to have the functions you previously used, plus the functions that you have input since you ran the hook last. There are many, many, more ways to do this. Some more extravagant than others. This is just a small example of what can be done, with very few lines of code. RE: Simple PHP Hooking - Gaijin - 05-14-2011 PHP and it's endless powers.... I see you are not passing by reference in Hook::add(), you should try it out. IMO, it is better if you pass the instance of an object to the function instead of creating a new instance within it. "&$hook" PHP Code: public function add(&$hook,$class=null,$method=null,$args=null) btw... The syntax may scare some people ;) Keep up the good work... RE: Simple PHP Hooking - Sly - 05-14-2011 $hook isn't meant to be referenced. $hook is the name of the hook that you will use in run($hook) to execute the hooks that are defined with that name. |