Re: Looking for caveats to the following code
| From: | Robert Cummings | Date: | Fri, 18 Aug 2006 00:04:44 +0000 |
| Subject: | Re: Looking for caveats to the following code | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-240837@lists.php.net to get a copy of this message | ||
On Thu, 2006-08-17 at 18:58 -0400, tedd wrote:
> At 3:19 PM -0700 8/17/06, Chris W. Parker wrote:
> ><?php
> >
> >if($result = do_something('hello'))
> >{
> > // do something with $result
> >}
> >else
> >{
> > // do some other stuff
> >}
> >
> >?>
> >
> >The issue is whether or not this is a safe test. My initial thought is
> >that it is safe since I'm simply checking for true/false-ness. I either
> >check for '!== false' explicitly or (in the case of the latter example)
> >check that something other than 'false' is returned.
> >
> >It's slightly less readable but it seems more efficient (if nothing more
> >than to save on the number of lines typed).
> >
> >Thoughts?
>
> Chris:
>
> You can shorten it even further by:
>
> if(do_something('hello'))
> {
> // do something with $result
I'm guessing you missed the content of the comment Tedd... he actually
needs the $result :D
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'