Class ErrorException and inheritance
- From: Werner Elflein <*@mueller-elflein.de>
- Date: Thu, 05 Mar 2009 15:59:02 +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: Werner Elflein
- Re: Class ErrorException and inheritance
- Prev by Date: Re: session management with database: optimal parameters in php.ini
- Next by Date: Re: (Sloppy correction) Re: session management with database: optimal parameters in php.ini
- Previous by thread: PHP code generates JSON but does not load Dojo Combobox if the class is cached in a $_SESSION array
- Next by thread: Re: Class ErrorException and inheritance
- Index(es):
Relevant Pages
|