|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Mar 28 20:00:02 2026 UTC |
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.