Current understanding of Hooks:< Reprint:http://www.cnblogs.com/del/archive/2008/02/25/1080825.html>
For example, we use the mouse to double-click on a window, or to a window to enter a letter A;
The first to discover these events is not the window, but the system!
Then the system tells the window: Hey! You got a point, and you've got two mouse clicks, what are you going to do?
Or the system tells the window: Hey! Someone threw bricks at your house, don't believe you look, that brick is a.
At this point the window is ignored for some events and responds to some events:
For example, the mouse click event may be ignored, the window wants to: you click I do not matter, exhausted you I am not responsible;
But once anyone wants to double-click me, I will act immediately, give you some color to see see!
The action that the window prepares to take is the event we have written in advance.
In the words of Windows, the event of a window is the message that the system sends to the window; The action (event code) to be taken by the window is the callback function of the window.
But! Often walls have ears. The system will be notified to the window "words" (messages), may be another guy (such as a thief) to hear in advance!
It is possible that this thief is specialized in such information, thieves know, often in the window before the action taken!
And the thief will take a different action plan for different news, and its action plan is generally ready;
Of course, the thief is not interested in any news, the information is not interested in the need to develop a corresponding action plan.
Summary: This "thief" is the hook we want to set; The "Thief" 's "Action Plan" is a hook function, or a callback function called a hook.
Officially started ...
If there is such a procedure:
function Fun () {
Fun1 ();
Fun2 ();
}
First the program executes FUN1 () after executing fun2 () and then fun () ends.
But, if we want to make some changes to the function. For example, fun is an analytic function, we hope that later can provide a rich analytic function, and which function to parse, we want to configure in the configuration file. The power of the hook can be played at this time.
We can put a hook point h in function Fun () {} and then execute the function of H, and then configure the hook function so that I can parse it as needed.
For example:
$h =config_item ("Parser_fun"); // Get the appropriate configuration information from the configuration file
function Fun ($data) {
$h;
$h ();
}
In addition to this accident, PHP can also provide its own class based on the string, and then invoke a method of the class, passing some parameters, which for the PHP program writing, as well as the later maintenance extension laid a fairly solid foundation.
Classes are implemented in the following ways:
get the name of the class
get the name of the method
$k = amethod of $c// execution class
PHP hook function principle Analysis