note 89132 added to class.errorexception
| From: | luke at cywh dot com | Date: | Mon, 23 Feb 2009 19:56:35 +0000 |
| Subject: | note 89132 added to class.errorexception | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151028@lists.php.net to get a copy of this message | ||
To add to the comments made by chris AT cmbuckley DOT co DOT uk about the ErrorException problem
with args:
I noticed that the problem is in the ErrorException class itself, not the Exception class. When
using just the exception class, it's no longer an issue. Besides the args problem, the only
difference between Exception and ErrorException in the stack trace is that the args are left out of
the error handler exception function. I'm not sure if this was on purpose or not, but it
shouldn't hurt to show this information anyway.
So instead of using this broken extended class, you can ignore it and make your own extended class
and avoid the problem all together:
<?php
header('Content-Type: text/plain');
class ErrorHandler extends Exception {
protected $severity;
public function __construct($message, $code, $severity, $filename, $lineno) {
$this->message = $message;
$this->code = $code;
$this->severity = $severity;
$this->file = $filename;
$this->line = $lineno;
}
public function getSeverity() {
return $this->severity;
}
}
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorHandler($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler", E_ALL);
function A() {
$foo->bar; // Purposely cause error
}
function B($c) {
A();
}
try {
B('foobar');
} catch (Exception $e) {
var_dump($e->getTrace());
}
?>
The only thing I wish I could do was remove the entry for the error handler function because
it's quite irrelevant. Maybe that's what they were trying to do with the ErrorException
class? Either way, you can't change it because the trace functions are final, and the variable
is private.
----
Server IP: 64.71.164.2
Probable Submitter: 74.93.181.202
----
Manual Page -- http://www.php.net/manual/en/class.errorexception.php
Edit -- https://master.php.net/note/edit/89132
Del: integrated -- https://master.php.net/note/delete/89132/integrated
Del: useless -- https://master.php.net/note/delete/89132/useless
Del: bad code -- https://master.php.net/note/delete/89132/bad+code
Del: spam -- https://master.php.net/note/delete/89132/spam
Del: non-english -- https://master.php.net/note/delete/89132/non-english
Del: in docs -- https://master.php.net/note/delete/89132/in+docs
Del: other reasons-- https://master.php.net/note/delete/89132
Reject -- https://master.php.net/note/reject/89132
Search -- https://master.php.net/manage/user-notes.php