RE: [PHP] Re: Looking for caveats to the following code

From: Date: Fri, 18 Aug 2006 10:23:47 +0000
Subject: RE: [PHP] Re: Looking for caveats to the following code
Groups: php.general 
Request: Send a blank email to php-general+get-240843@lists.php.net to get a copy of this message
On 17 August 2006 23:28, Adam Zey wrote: > > Better to do this: > > if ( ($result = do_something('hello')) !== false ) > { > // do something with $result > } > else > { > // do some other stuff > } > > The result of an assignment like "$result = do_something('hello')" is > itself the result you assigned, so you can still compare on that. The > reason I put it in more brackets was just for readability. I > don't think > you actually need the extra set, but I'm not sure. Of course you do -- without them, it's the equivalent of: if ( $result = (do_something('hello') !== false) ) which will only assign TRUE or FALSE to $result. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

« previous php.general (#240843) next »