php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15791 set_error_handler() can not be used to set error control to a class function
Submitted: 2002-02-28 14:26 UTC Modified: 2002-06-12 20:53 UTC
From: ned at wgtech dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.1.1 OS: All
Private report: No CVE-ID: None
 [2002-02-28 14:26 UTC] ned at wgtech dot 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-28 17:38 UTC] 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-06-12 20:53 UTC] sniper@php.net
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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC