paradigmapc Posted December 3, 2007 Share Posted December 3, 2007 I'm sure there is a perfectly logical explanation behind this but why does print (0 == "STRING") ? "0 is equal to STRING" : "0 is not equal to STRING"; print 0 is equal to STRING no need to say to the identity operator "===". I'm just curious to the reason of why "STRING" would be converted to zero during the comparison. Thanks Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/ Share on other sites More sharing options...
cooldude832 Posted December 3, 2007 Share Posted December 3, 2007 welll you aren't converting aynthing you are using a print which is a function itself and doesn't take an else if operator Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404746 Share on other sites More sharing options...
cooldude832 Posted December 3, 2007 Share Posted December 3, 2007 <?php if(0 == "STRING"){ echo "0 = STRING"; } else{ echo "0 != STRING"; } ?> Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404747 Share on other sites More sharing options...
paradigmapc Posted December 3, 2007 Author Share Posted December 3, 2007 This code still prints "0 = STRING": <?php if(0 == "STRING"){ echo "0 = STRING"; } else{ echo "0 != STRING"; } ?> as does: print (0 == "STRING") ? "0 is equal to STRING" : "0 is not equal to STRING"; I think you may have misunderstood by question: Within the if statement 0 and "STRING" are being compared but because the identity operator (===) was not used string is being converted to a int in order to be compared. Why does a string convert to 0 when being compared to an int? My guess is that what ever is converting the string to an int is returning zero because it cant be converted, but I am not sure, and then again my whole thought process of the event could be wrong. Sorry for the confusion. Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404762 Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 This looks like a bug to me. "STRING" should actually equate to 1 (true). <?php echo ('STRING') ? 'true' : 'false'; // returns as expected true. echo ('STRING' == TRUE) ? 'true' : 'false'; // returns as expected true. echo ('STRING' == FALSE) ? 'true' : 'false'; // returns as expected false. echo ('STRING' == 0) ? 'true' : 'false'; // returns as NOT expected true. ?> Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404879 Share on other sites More sharing options...
lur Posted December 3, 2007 Share Posted December 3, 2007 This looks like a bug to me. "STRING" should actually equate to 1 (true). Nope. (int) 'STRING' = 0; (bool) 'STRING' = TRUE; Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404939 Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 This looks like a bug to me. "STRING" should actually equate to 1 (true). Nope. (int) 'STRING' = 0; (bool) 'STRING' = TRUE; Yeah, I realise now that a string is converted to an int (with a value of 0) when compared with an int. Link to comment https://forums.phpfreaks.com/topic/79916-value-of-0/#findComment-404988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.