Re: How would you code: $r = func() or return 0?
| From: | Markus Fischer | Date: | Wed, 26 Sep 2001 19:40:00 +0000 |
| Subject: | Re: How would you code: $r = func() or return 0? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-2070@lists.php.net to get a copy of this message | ||
Hey, actually a good question.
Personally I try to return false(bool) wherever I can and check
it this way
if (false === ($result = foo_var()))
- Markus
On Wed, Sep 26, 2001 at 02:55:24PM -0400, scott [gts] wrote :
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Since there are various emails flying around this list
> asking for comments on coding style, comment style, etc.
> I thought i'd ask for your comments on how you'd code this
> common perl code with PHP:
>
> $value = some_function() or return 0;
>
> i usually code my functions to return 0 or "" on error, but
> have to use the following code to handle it... neither seem
> like a good solution to me.
>
> this way decreses the readability of the code:
> if (!$value = some_function)
> return 0;
>
> and this way adds an unnecessary if() statement:
> $value = some_function()
> if (!$value) {
> return 0;
> }
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use
> <http://www.pgp.com>
>
> iQA/AwUBO7Ikm8aXTGgZdrSUEQL/pgCdGQoZLHMH3JtE0qr0t0GGR5fDSVAAn1Nr
> A6IKTQ6ebnm/XZPpcOVxVOLm
> =05Xf
> -----END PGP SIGNATURE-----
>
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Markus Fischer, http://guru.josefine.at/~mfischer/
EMail: mfischer@guru.josefine.at
PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
-All your scripts are belong to Zend-