Re: Re: Re:[PHP-WIN] Strange 'if' test bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Steve,

0 and "foo" are two different types (int and string). In order to compare
these values they must be converted into the same type. PHP does that by
converting "foo" to an integer and that value will be 0, hence the true
value on compare with ==. when you use === to compare the two values need
to be of the same type to evaluate to true.

you can trick the compare by doing stuff like this:

if ("$key" == "muppet") (
}

- Frank

> Well gee, thanks a lot for that....
> 
> I can't imagine why 0 == "foo" should be TRUE, but there it is.... I
will
> use === from now on.
> 
> I was convinced this was related to windows because I've never noticed
this
> behaviour with several years of experience with programming PHP on
linux
> systems.
> 
> Thanks for your patience, and your answer.
> 
> Best wishes,
> Steve
> 
> "Nadim Attari" <nadim@xxxxxxxxxxxxxxxx> schreef in bericht
> news:20040831111350.90008.qmail@xxxxxxxxxxxxxxx
> > http://www.blueshoes.org/en/developer/php_cheat_sheet/
> > ------------------
> >
> > "William.Candillon@xxxxxxxxxx" <william.candillon@xxxxxxxxxx> a écrit
dans
> > le message de
news:I3B3VI$0DB29DE9F5BD09BECC716F6E620D2A44@xxxxxxxxxxxxx
> > According to me it's a very strange problem
> > Test this please :
> > $key = '0';
> > if($key == 'muppet')
> >    echo 'key is a muppet: ".$key;
> > else
> >    echo 'key is something else: '.$key;
> > Because I don't understang why $key return false :(
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux