Given this code:
class CallbackClass {
function CallbackFunction() {
// refers to $this
}
function StaticFunction() {
// doesn't refer to $this
}
}
function NonClassFunction() {
}
there appear to be 3 ways to set a callback function in PHP (using set_error_handler() as an example):
1: set_error_handler('NonClassFunction');
2: set_error_handler(array('CallbackClass', 'StaticFunction'));
3: $o =& new CallbackClass();
set_error_handler(array($o, 'CallbackFunction'));
The following may also prove useful:
class CallbackClass {
function CallbackClass() {
set_error_handler(array(&$this, 'CallbackFunction')); // the & is important
}
function CallbackFunction() {
// refers to $this
}
}
The documentation is not clear in outlining these three examples.