Re: Looking for caveats to the following code
| From: | Anas Mughal | Date: | Fri, 18 Aug 2006 01:10:58 +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-240838@lists.php.net to get a copy of this message | ||
Tedd,
Actually, he seems to be needing the return value of the function inside the
if block. So, he would need to do:
if ($result = do_something('hello'))
or, as Adam stated:
if ( ($result = do_something('hello')) !== false )
Regards.
--
Anas Mughal
On 8/17/06, tedd <tedd@sperling.com> 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'))-- Anas Mughal{// do something with $result}else{// do some other stuff}I don't think it's any different than calling any other function that returns <whatever> or false. I tried it out at -- http://xn--ovg.com/a14.php -- with both pass and fail. All worked the same in all three ways. hth's tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php