NYCPHP Meetup

NYPHP.org

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

Nunez, Eddy enunez at tiaa-cref.org
Fri Jul 2 11:24:13 EDT 2004


Well that sure is interesting.
Anyone with intimate knowledge of PHP internals care to answer this one?


-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Brian Kaney
Sent: Friday, July 02, 2004 11:19 AM
To: NYPHP Talk
Subject: [nycphp-talk] What's going on here? PHP conditional.


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.boole
an.casting


- Brian


_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk


**************************************************************
This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, please contact sender immediately by reply e-mail and destroy all copies.  You are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.
TIAA-CREF
**************************************************************




More information about the talk mailing list