Class ErrorException and inheritance
- From: Werner Elflein <*@mueller-elflein.de>
- Date: Thu, 05 Mar 2009 15:54:52 +0100
Hello all,
maybe one of you can give me an answer to the following question:
Since PHP 5.3, the class \ErrorException (which extends \Exception) has
the constructor
ErrorException::__construct
(
[ string $message
[, long $code
[, long $severity
[, string $filename
[, long $lineno
[, Exception $previous = NULL
]]]]]]
)
By default, the object $e coming up with
[1] try
[2] {
[3] throw new ErrorException($message, $code, $severity);
[4] }
[5] catch (ErrorException $e)
[6] {
[7] }
has methods $e->getFile() and $e->getLine() which return the filename
resp. the line number where the exception was thrown.
Assume, you define a new class
SuperErrorException extends ErrorException,
the constructor of the subclass should at least contain the same
parameters, e.g.
namespace Super;
class SuperErrorException extends \ErrorException
{
public function __construct
(
$message = '',
$code = 0,
$severity = 0,
$filename = NULL, (A)
$lineno = NULL, (B)
Exception $previous = NULL
)
{
parent::__construct
(
$message,
$code,
$severity,
$filename,
$lineno
);
}
}
Here, $filename and $lineno are NULL by default to make the parameters
optional (as in ErrorException).
The problem:
[1] try
[2] {
[3] throw new SuperErrorException($message, $code, $severity);
[4] }
[5] catch (ErrorException $e)
[6] {
[7] }
will call SuperErrorException::__construct which overwrites the defaults
for $filename and $lineno with NULL.
Replacing $filename and $lineno in (A) and (B) by __FILE__ and __LINE__
is not the solution!
What can be done to give SuperErrorException the same core functionality
as ErrorException?
Kind regards,
Werner
.
- Follow-Ups:
- Re: Class ErrorException and inheritance
- From: Umberto Salsi
- Re: Class ErrorException and inheritance
- Prev by Date: Re: Eclipse PDT terminates at: $row = @$result->fetch_assoc()
- Next by Date: Re: Prom deleting directory when using recursive mkdir
- Previous by thread: Prom deleting directory when using recursive mkdir
- Next by thread: Re: Class ErrorException and inheritance
- Index(es):
Relevant Pages
|