Re: error handling and conditional inclusion of PEAR.php

From: Date: Sun, 30 May 2004 12:18:59 +0000
Subject: Re: error handling and conditional inclusion of PEAR.php
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-12802@lists.php.net to get a copy of this message
On 30 May 2004 at 11:51, Demian Turner wrote: > according to a recent post in Harry F's blog that picked up a few interesting > comments [1], many developers using PEAR libs are not extending from the base > PEAR class and only including it 'on demand' once errors are thrown. > > I can see how that would work in a situation where PEAR::raiseError() is > wrapped, which is quite typical, but how about PEAR::isError() ? > > Eg, in simple Config code, PEAR.php would need to be loaded to handle potential > errors: > > $c = new Config(); > // read configuration data and get reference to root > $root = & $c->parseConfig($conf, 'phparray'); > // write configuration to file > $result = $c->writeConfig('...', 'inifile'); > if (!PEAR::isError($result)) { > // ... > } > > feedback appreciated :-) Hi, you have to at least include PEAR.php, but not extend from it. PEAR::isError() is a static call - so there is no need that the class extends from PEAR. However, you are true that for every script using isEror() PEAR.php would have to be loaded - which might be unnecessary overhead in certain scripts. Therefor afaik some people are using is_a($result, 'PEAR_Error') ... maybe that would be a cleaner solution to the problem, since you won't have to include PEAR.php just for the check? Stefan

« previous php.pear.general (#12802) next »