What is hook in phpwind-php?

Source: Internet
Author: User
I often encounter hooks when I look at the phpwind source code, but after searching for it for a long time, I still have a clue about it. I don't want to know this. The predecessors can give me a more detailed explanation or relevant links. when phpwind source code is used, hook is often encountered.
But after searching for a long time, I still have no clue about this.
I hope the predecessors who know this can give a more detailed explanation or related links.

Reply content:

When you look at the phpwind source code, you often encounter hook
But after searching for a long time, I still have no clue about this.
I hope the predecessors who know this can give a more detailed explanation or related links.

Close the MySQL database connection at the end of the script:


  close();    }}register_shutdown_function('close_db', $app, $mysqli);

Register_shutdown_function is a hook-type function that triggers certain operations when a specific event occurs (the script is disabled) (The close_db function is called to close the database ).

For example, if you want to create a comment sensitive word filter plug-in, you should call your filter function (hook function) when the comment is output (event), and then continue to output the comment. the add_filter/add_action function in WordPress is used to implement hooks.

PHP implementation hook and plug-in system
Http://stackoverflow.com/questions/8336308/how-to-do-a-php-hook-system

/*** Attach (or remove) multiple callbacks to an event and trigger those callbacks when that event is called. * bind or remove multiple callback functions to events. When an event is called, The callback function is triggered. ** @ param string $ event name * @ param mixed $ value the optional value to pass to each callback * @ param mixed $ callback the method or function to call-FALSE to remove all callbacks for event */function event ($ event, $ value = NULL, $ callback = NULL) {stat Ic $ events; if ($ callback! = NULL) {if ($ callback) {$ events [$ event] [] = $ callback; // Add event} else {unset ($ events [$ event]); // remove all callback functions in the event} else if (isset ($ events [$ event]) {foreach ($ events [$ event] as $ function) {$ value = call_user_func ($ function, $ value); // call event} return $ value ;}// add event ('filter _ text', NULL, function ($ text) {return htmlspecialchars ($ text) ;}); event ('filter _ text', NULL, function ($ text) {return nl2br ($ text) ;}); // remove all callback functions in the event // event ('filter _ text', NULL, FALSE ); // call event $ text = event ('filter _ text', $ _ POST ['text']);

HOOK is the HOOK, which is also the core mechanism of drupal and wordpress. In fact, it is equivalent to event binding. If you hook up somewhere, you can inject code elsewhere.

This is generally used to represent the plug-in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.