PEAR_Error
| From: | Ulf Wendel | Date: | Tue, 12 Sep 2000 12:22:27 +0000 |
| Subject: | PEAR_Error | ||
| Groups: | php.pear | ||
| Request: | Send a blank email to php-pear+get-247@lists.php.net to get a copy of this message | ||
Hi,
I had a look at the PEAR Error class and there're two things I
didn't like.
1. Constructor
The constructor takes four optional parameters. $message, $code,
$mode and $level. $mode (PEAR_ERROR_RETURN) and $level
(E_USER_NOTICE) have certain default values and override the
instance variables $this->mode/$this->level. If $level and $mode
would have empty strings as a default value we could decide
wheter to override the instance variables with the values passed
to the constructor or leave it as is.
now:
function PEAR_Error( $message = "unknown error",
$code = 0,
$mode = PEAR_ERROR_RETURN,
$level = E_USER_NOTICE
) {
$this->message = $message;
$this->code = $code;
$this->mode = $mode;
$this->level = $level
...
suggestion:
function PEAR_Error( $message = "unknown error",
$code = 0,
$mode = "",
$level = ""
) {
$this->message = $message;
$this->code = $code;
if ( ""!=$mode ) $this->mode = $mode;
if ( ""!=$level ) $this->level = $level
advantage:
Using this more "conservative" contructor you can have error
classes that inherit a default behavior from their parents. The
parent would not only set $error_message_prefix but $mode and
$level.
2. $this->mode
PEAR_Error() uses switch($this->mode) to eigther print the
message, passes the message to the custom error handler using
trigger_error(), to call die() or to do simply nothing. But I
can't print the message -and- call die(). How about something
like:
if ($this->mode & PEAR_ERROR_PRINT) ...
if ($this->mode & PEAR_ERROR_TRIGGER) ...
...
Ulf
--
Ulf Wendel
NetUSE AG, Siemenswall, 24107 Kiel, Germany
Fon: +49 431 386435 00 -- Fax: +49 431 386435 99