>     $a == $b != NaN
   > 
   > really means this:
   > 
   >     $a == $b && $b != NaN
   > 
   > But "$a == $b != NaN" is supposed to "[solve] the problem of numerical
   > comparisons between non-numeric strings."  Well, what if:
   > 
   >     $a = 'hello';
   >     $b = 0;
   > 
   > Doesn't that mean:
   > 
   >     "hello" == 0 && 0 != NaN
   > 
   > will evaluate to true?
   
No. The step you're missing is that the non-numeric string "hello",
when evaluated in a numeric context, produces NaN. So:

         "hello" == 0 && 0 != NaN

is:

         Nan == 0 && 0 != NaN

which is false.

And in the reverse case:

         $a = 0;
         $b = 'hello';
     
then:

         $a == $b != NaN
    
is:
    
         $a == $b && $b != NaN
     
is:

         0 == "hello" && "hello" != NaN

is:

         0 == NaN && NaN != NaN

which is false too.

The C<!= NaN> is really only needed to cover the third case:

         $a = 'goodbye';
         $b = 'hello';
     
when:

         $a == $b != NaN
    
is:
    
         $a == $b && $b != NaN
     
is:

         "goodbye" == "hello" && "hello" != NaN

is:

         NaN == NaN && NaN != NaN

which is false as well.

Damian

Reply via email to