Call back functions. Methods and precautions for using the PHPcallback function. Some callback functions in PHP, such as call_user_function () or usort (), use user-defined functions as a parameter. Ca PHP callback function usage and precautions, callback function
Some functions in PHP, such as call_user_function () or usort (), use user-defined functions as a parameter. The Callback function can be not only a simple function, but also an object method, including a static class method.
A php function is passed using a function name string. You can pass any built-in or user-defined functions except array (), echo (), empty (), eval (), exit (), isset (), list (), print (), and unset ().
The method of an object is transmitted as an array. the 0 subscript of the array indicates the object name, and the subscript 1 indicates the method name.
For a static class that is not instantiated as an object, pass its method and replace the object name specified by the array 0 subscript with the name of this class.
Callback function instance:
The code is as follows:
<? Php
// An example callback function
Function my_callback_function (){
Echo 'Hello world! ';
}
// An example callback method
Class MyClass {
Function myCallbackMethod (){
Echo 'Hello World! ';
}
}
// Type 1: Simple callback
Call_user_func ('My _ callback_function ');
// Type 2: Static class method call
Call_user_func (array ('myclass', 'mycallbackmethod '));
// Type 3: Object method call
$ Obj = new MyClass ();
Call_user_func (array ($ obj, 'mycallbackmethod '));
?>
Http://www.phpe.net/manual/language.pseudo-types.php
Http://cn.php.net/manual/en/language.pseudo-types.php
Http://www.bkjia.com/PHPjc/946743.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/946743.htmlTechArticlePHP callback functions use methods and notes, callback functions in PHP some functions such as call_user_function () or usort () accept user-defined functions as a parameter. Ca...