Some functions like call_user_func()
or usort() accept user defined
callback functions as a parameter. Callback functions can not only
be simple functions but also object methods including static class
methods.
A method of an instantiated object is passed as an array containing
an object as the element with index 0 and a method name as the
element with index 1.
Static class methods can also be passed without instantiating an
object of that class by passing the class name instead of an
object as the element with index 0.
Example 11-13.
Callback function examples
<?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')); ?>