On Thu, Aug 26, 2010 at 2:11 PM, Hector Virgen <[email protected]> wrote:

> PHP is a loosely-typed language, meaning that the empty string '' will
> evaluate to false unless you do strict comparisons (=== and !==). For
> example:
>
> $test = FALSE;
>
> if ('' != $test) {
>     // this executes because of loose typing
> }
>
> if ('' !== $test) {
>    // this doesn't execute because of strict comparison
> }
>
> When testing function return values that may return a number or FALSE, it
> is best to use strict comparisons:
>
> while(false !== ($attribute = $result->fetch_assoc())) {
> ...
> }
>
> --
> **
>


As I understand it, one reason for putting the literal on the left side of a
comparison test is to safeguard against introducing a typo/bug when you
mistakenly type '='  instead of '=='  or '==='

if ($foo = 346)  {


}

which in fact is an idiom some of us are fond of, i.,e assigning values
inside conditionals

if ($foo = $this->_getParam('something_verbose')) {
         // work with $foo

}



-- 
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/

Reply via email to