Re: Re: poll: howto do informative error handling without the fatalities
| From: | Paul M Foster | Date: | Wed, 10 Feb 2010 02:04:35 +0000 |
| Subject: | Re: Re: poll: howto do informative error handling without the fatalities | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-301917@lists.php.net to get a copy of this message | ||
On Tue, Feb 09, 2010 at 11:38:42PM +0100, Rene Veerman wrote:
> Well, i've thought of a few ways to allow localized overriding of
> values returned by functions in case of an error.
>
> I have yet to figure out what the exact advantages are of this
> code-standard, but the overhead seems acceptable and i recon this,
> when done, will beat the "trigger_error()-try-catch" paradigm.
> I'd like to hear your comments.
>
> // imo unsafe & prone to fatalities:
> $r = funcA ( funcB ( funcC ($p) ), funcD ($q) );
I wasn't going to comment, but seriously, Rene, I would not make it a
habit of calling functions within the parameters of other functions.
Among other things, it obviously creates a whole host of the problems
you're talking about, and it makes your code hard to debug and read. The
only way I'd normally do something like this is if I were using native
PHP functions and the possible failure of the functions wouldn't matter.
Rather, I'd do something like this:
$d = funcD($q);
// tests if necessary
$c = funcC($p);
// tests if necessary
$b = funcB($c);
// tests if necessary
$r = funcA($b, $d);
Paul
--
Paul M. Foster