Bug #15791 Updated: set_error_handler() can not be used to set error control to a class function

From: Date: Thu, 13 Jun 2002 00:53:12 +0000
Subject: Bug #15791 Updated: set_error_handler() can not be used to set error control to a class function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-10295@lists.php.net to get a copy of this message
ID: 15791 Updated by: sniper@php.net Reported By: ned@wgtech.com -Status: Duplicate +Status: Closed Bug Type: Feature/Change Request Operating System: All PHP Version: 4.1.1 New Comment: This bug has been fixed in CVS. You can grab a snapshot of the CVS version at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2002-06-12 20:52:46] cox@php.net http://bugs.php.net/bug.php?id=9155 ------------------------------------------------------------------------ [2002-02-28 17:38:35] mfischer@php.net This request is valid (it's a limitation of the current implementation in zend_builtin_functions.c) but your analysis wasn't very accurat. Methods of Static Classes or objects are normally passed with the syntax array($obj, 'method'); or array('class', 'method'); Anyway, it's an open feature request. ------------------------------------------------------------------------ [2002-02-28 14:26:17] ned@wgtech.com Heres the long and short of it: set_error_handler() wants a string as the name of the function that will handle errors. However, if you create a class and try to assign error handling to a function within the class, there is no way to reference that function. For example class ApplicationObject { var $error_List as array(); function ApplicationObject() { set_error_handler('trapError'); } function trapError($err_no, $err_str, $err_file, $err_line, $err_context) { echo "Trap error caught error ".$err_no; } } // *** Now create the object *** $app = new ApplicationObject(); trigger_error ("Cannot divide by zero", E_USER_ERROR); This doesn't work. Nor does changing set_error_handler('trapError') to set_error_handler('$this->trapError'). Removing the quotes just executes the function. Removing the assignment of error handling outside of the class like so: $app = new ApplicationObject(); set_error_handler('$app->trapError'); trigger_error ("Cannot divide by zero", E_USER_ERROR); Since the error handling function will need access to $error_List and I sure dont want to GLOBAL it, this kind of makes things difficult. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15791&edit=1

« previous php.bugs (#10295) next »