doubledee Posted June 17, 2012 Author Share Posted June 17, 2012 So ignorance then. Got it. SO filled with self-loathing... *LMAO* Go whine in another thread... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264349-why-is-this-evalutaing-to-true/page/2/#findComment-1354719 Share on other sites More sharing options...
Pikachu2000 Posted June 17, 2012 Share Posted June 17, 2012 You started this festering little donnybrook. Shall I go ahead and end it for you? I have no problem doing so, believe me. Quote Link to comment https://forums.phpfreaks.com/topic/264349-why-is-this-evalutaing-to-true/page/2/#findComment-1354720 Share on other sites More sharing options...
doubledee Posted June 17, 2012 Author Share Posted June 17, 2012 I knew that was so in an IF condition, but I did not know that if you put any non-zero value in a logical comparison that it would evaluate to TRUE. It has to do with how PHP decides to interpret the types for the comparison. Since your testing a boolean==integer, php decides to cast the integer to a boolean and evaluate the condition as boolean==boolean. I thought the exact OPPOSITE was happening... I thought PHP turned TRUE into "1" and so 1 would never equal 999. Interesting... so: $preview == 999 becomes TRUE == (boolean)999 which becomes TRUE == TRUE. Hey, that's cool. Thanks for the explanation! You can force php to interpret something a specific way by doing your own casting, such as: if ((int)$preview == 999): which would force php to cast $preview to an int (1) then evaluate 1 == 999, which would be false. And that is how I thought things were working. (PHP does things a lot differently than languages like Java, C, and C++) Thanks for the extra information!! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264349-why-is-this-evalutaing-to-true/page/2/#findComment-1354722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.