NYCPHP Meetup

NYPHP.org

[nycphp-talk] What's going on here? PHP conditional.

Brian Kaney brian at vermonster.com
Fri Jul 2 11:18:44 EDT 2004


Just came across this problem.  Consider the following code:

<?php

echo "Equivalent: ";
if (0 == 'Some String') { echo 'evaluates true'; } else { echo
'evaluates false'; }

echo "\n";

echo "Equivalent and same type: ";
if (0 === 'Some String') { echo 'evaluates true'; } else { echo
'evaluates false'; }

?>

I get 

Equivalent: evaluates true
Equivalent and same type: evaluates false



Does anyone know why (0 == 'string') evaluates to true?   

According to the manual, the integer 0 converts to FALSE.  A non-empty
(or non-zero) string is considered TRUE. I would think if (FALSE ==
TRUE) should be evaluated as false?

http://us2.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting


- Brian





More information about the talk mailing list