PHP 8.3.21 Released!

Voting

: zero plus five?
(Example: nine)

The Note You're Voting On

phpmanual at NO_SPHAMnetebb dot com
21 years ago
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.

<< Back to user notes page

To Top