Laogeodritt Posted July 24, 2008 Share Posted July 24, 2008 Hello, I recently encountered what seems to me as an odd behaviour in one of my scripts. Although I've quite easily fixed the problem, I can't figure this behaviour out at all, which is contrary to what I'd expect; I'd like to understand the reason behind it. For a non-empty, non-numeric string $var, the expression ($var != 0) seems to always evaluate to FALSE. I would have expected any non-empty non-zero string to cause this expression to evaluate to TRUE. Can anyone explain why PHP evaluates this expression like this? Thanks, Laogeodritt Link to comment https://forums.phpfreaks.com/topic/116334-solved-string-0-evaluates-to-false-why/ Share on other sites More sharing options...
DragonFire-N[R] Posted July 24, 2008 Share Posted July 24, 2008 http://us.php.net/manual/en/types.comparisons.php Perhaps this can explain why PHP does what it does Link to comment https://forums.phpfreaks.com/topic/116334-solved-string-0-evaluates-to-false-why/#findComment-598177 Share on other sites More sharing options...
Laogeodritt Posted July 24, 2008 Author Share Posted July 24, 2008 ... ack. I actually thought about those tables, but I only remembered the various variations of 1, 0, TRUE, FALSE and -1 being on there. Thanks for the reply ... and for not yelling at me. XD; Link to comment https://forums.phpfreaks.com/topic/116334-solved-string-0-evaluates-to-false-why/#findComment-598179 Share on other sites More sharing options...
.josh Posted July 24, 2008 Share Posted July 24, 2008 As to why.... http://us.php.net/manual/en/types.comparisons.php#49327 Link to comment https://forums.phpfreaks.com/topic/116334-solved-string-0-evaluates-to-false-why/#findComment-598180 Share on other sites More sharing options...
Laogeodritt Posted July 24, 2008 Author Share Posted July 24, 2008 Ah... all right, thanks, both of you. ^^; Link to comment https://forums.phpfreaks.com/topic/116334-solved-string-0-evaluates-to-false-why/#findComment-598183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.