Re: [PHP] Re: poll: howto do informative error handling without the fatalities

[email protected] (Paul M Foster)
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.