Re: does Pear_Error catch ALL php errors? if not, how do you guys catch all errors?
| From: | Matthew Weier O'Phinney | Date: | Sun, 07 Aug 2005 14:57:35 +0000 |
| Subject: | Re: does Pear_Error catch ALL php errors? if not, how do you guys catch all errors? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20313@lists.php.net to get a copy of this message | ||
* l Burnerheimerton <lburnerheimerton@yahoo.com>:
> I have a little experience with PEAR and like the
> packages I've used. I want to take my development to
> the next level and look at catching all errors in a
> uniform way.
>
> It looks like Pear_Error catches Pear erros only, not
> all php errors. Is that correct?
Correct.
> If it's correct, how do you guys capture all erros for
> uniform error processing?
Using PHP's native set_error_handler()
(http://php.net/set_error_handler). If you don't specify arguments in
your function, you can use the func_* args to determine if an error was
a PHP or a PEAR error, and use the error handler to handle both:
function errors()
{
$numArgs = func_num_args();
switch ($numArgs) {
case 1:
$arg = func_get_arg(0);
if (is_string($arg)) {
// Just a string passed
$message = $arg;
break;
}
// PEAR error
$msg = $arg->getMessage();
break;
case 5:
default:
// PHP error
$msg = func_get_arg(1);
break;
}
exit($message);
}
set_error_handler('errors');
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errors');
(Untested, and pretty much pointless, but it gives the general idea.)
--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/