Bug #15791: set_error_handler() can not be used to set error control to a class function
| From: | ned at wgtech dot com | Date: | Thu, 28 Feb 2002 19:26:18 +0000 |
| Subject: | Bug #15791: set_error_handler() can not be used to set error control to a class function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-1316@lists.php.net to get a copy of this message | ||
From: ned@wgtech.com
Operating system: All
PHP version: 4.1.1
PHP Bug Type: Feature/Change Request
Bug description: set_error_handler() can not be used to set error control to a class function
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 bug report at http://bugs.php.net/?id=15791&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=15791&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=15791&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=15791&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=15791&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=15791&r=support
Expected behavior: http://bugs.php.net/fix.php?id=15791&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=15791&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=15791&r=submittedtwice