Thanks David, I have just started a new job and the code base uses the form:

while($attribute = $result->fetch_assoc()) {

}

I believe this just doesnt sit right, well with me any way, althoug I
understand its also not a major point, but I started to use:

while(false !== ($attribute = $result->fetch_assoc())) {

}

My lead developer says there is no need but I just couldn't articulate
why it was better/safer ( i thought, especially in enterprise app )
the way I did it.

Now I have some ammo :) Thanks guys.

Dan

On 26 August 2010 19:25, David Mintz <[email protected]> wrote:
>
>
> 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