RE: [PHP-PEAR] error handling

From: Date: Thu, 01 Feb 2001 20:11:27 +0000
Subject: RE: [PHP-PEAR] error handling
References: 1  Groups: php.pear 
Request: Send a blank email to php-pear+get-1234@lists.php.net to get a copy of this message
> class myErrorClass extends PEAR_Error { > > function myErrorClass($code) { > $mode = PEAR_ERROR_CALLBACK; > $callback = "default_error_callback"; > > if (in_array($code, $this->warn_errors)) { > $callback = "error_callback"; > } else if (in_array($code, $this->fatal_errors)) { > $callback = "fatal_error_callback"; > } > > $this->PEAR_Error('Some error', $code, $mode, $callback) > } > } > > (Your example returned a PEAR_Error object from its constructor rather > than calling the inherited constructor, I've shown "the intended way" in > the example above.) Hmm ... this works well, except that for the "default_error_callback", I'd like my function to return the error object. I tried changing your line back to return $this->PEAR_Error('Some error', $code, $mode, $callback); And also set: function default_error_callback($err) { if (error_reporting() & E_NOTICE) { echo "<br>\n"; printf("<b>Notice</b>: %s [%d]\n", $err->message, $err->code ); } return $err; } But that doesn't seem to do it (I admit that callbacks are confusing me a wee bit). If it makes it any clearer, I have myClass() and myErrorClass(). If myClass generates an error, it will invoke myErrorClass(). If the error was fatal, it should say so and die. If not, then it should just return the error object so the user's script can proceed accordingly. Am I approaching this entirely wrong? - Colin

« previous php.pear (#1234) next »