php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #20072 set_error_handler doesn't accept Class::function()
Submitted: 2002-10-24 14:17 UTC Modified: 2004-01-10 09:51 UTC
From: mark at tapinternet dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.2.3 OS: mandrake-9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mark at tapinternet dot com
New email:
PHP Version: OS:

 

 [2002-10-24 14:17 UTC] mark at tapinternet dot com
set_error_handler() does not accept static class functions 
as a custom error handling function. 
 
set_error_handler('ErrorClass::handler') will not report 
false if called twice in succession.  But it will also not 
route errors through the static class function.  Either it 
should return false so that a script can realize the input 
was not handled properly, or it should route errors 
throught the static class function. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-24 15:17 UTC] hholzgra@php.net
the syntax for class method callbacks is

  set_error_handler(array("ErrorClass","handler"))

although i like your idea of how it could look like

moved to feature requests

 [2002-10-24 17:34 UTC] mark at tapinternet dot com
I don't think this is fully functional.  Correct me if I'm 
wrong but an error handler of  
"Class::function" 
and 
"function" 
should not function any different if they are the same 
code.  Use the code below, and uncomment each of the two 
set_error_handler() calls differnetly.  You will see that 
the plain function captures the error, while the 
Class::function does not. 
 
<? 
 
class ErrorClass { 
 
        function _errorHandler ($level, $message, $file, 
$line, $context) { 
                static $count; 
                print "\n\n got ".++$count." errors\n\n 
$message \n\n"; 
        } 
 
} 
 
        function _errorHandler ($level, $message, $file, 
$line, $context) { 
                static $count; 
                print "\n\n got ".++$count." errors\n\n 
$message \n\n"; 
 
        } 
 
 
 
 
//test code 
error_reporting (E_USER_ERROR | E_USER_WARNING | 
E_USER_NOTICE); 
 
//set_error_handler('_errorHandler'); 
 
//set_error_handler(array("ErrorClass","_errorHandler")); 
 
while( list($k,$v) = each($notarray) ) { 
//... 
} 
 
 
?>
 [2004-01-10 09:51 UTC] andrey@php.net
The example provided works wo any problems. Both handlers catch the error (PHP5-CVS). The array() syntax is the PHP way of passing a callback. Closing.

Thank you for the feature request.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 22:00:01 2025 UTC