class CallbackClass { function CallbackFunction() { // refers to $this } function static StaticFunction() { // doesn't refer to $this } } function NonClassFunction($errno, $errstr, $errfile, $errline) { } // 三种方法如下: 1: set_error_handler('NonClassFunction'); // 直接转到一个普通的函数 NonClassFunction 2: set_error_handler(array('CallbackClass', 'StaticFunction')); // 转到 CallbackClass 类下的静方法 StaticFunction 3: $o =& new CallbackClass(); set_error_handler(array($o, 'CallbackFunction')); // 转到类的构造函数,其实本质上跟下面的第四条一样。 4. $o = new CallbackClass(); // The following may also prove useful: class CallbackClass { function CallbackClass() { set_error_handler(array(&$this, 'CallbackFunction')); // the & is important } function CallbackFunction() { // refers to $this } }