PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
SmokyBarnable
Forum Contributor
Posts: 105 Joined: Wed Nov 01, 2006 5:44 pm
Post
by SmokyBarnable » Sun Feb 04, 2007 6:07 pm
That is only the case when it is a equality comparison to boolean, but there are many types of equality comparison in PHP.
Then how do you explain this?
Code: Select all
<?php
$result = var_dump((bool) 1);
echo $result;
$result = var_dump((bool) 0);
echo $result;
?>
bokehman
Forum Regular
Posts: 509 Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)
Post
by bokehman » Sun Feb 04, 2007 6:18 pm
SmokyBarnable wrote: Then how do you explain this?
Are you on a wind-up? Of 0 will equal false if you convert it to a boolean first but I don't see the connection between that and my comment that there are many types of equality comparison in PHP.
SmokyBarnable
Forum Contributor
Posts: 105 Joined: Wed Nov 01, 2006 5:44 pm
Post
by SmokyBarnable » Sun Feb 04, 2007 6:25 pm
I don't see the connection between that and my comment that there are many types of equality comparison in PHP.
I don't understand where the equality comparison is in this statment.
bokehman
Forum Regular
Posts: 509 Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)
Post
by bokehman » Sun Feb 04, 2007 6:32 pm
Unbalanced conditionals do an equality comparison to boolean.
SmokyBarnable
Forum Contributor
Posts: 105 Joined: Wed Nov 01, 2006 5:44 pm
Post
by SmokyBarnable » Sun Feb 04, 2007 6:48 pm
I see. So even if zero equates to false I shouldn't assume that it always will?
bokehman
Forum Regular
Posts: 509 Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)
Post
by bokehman » Sun Feb 04, 2007 7:01 pm
It only evalutes to false when checked as a boolean. If you start checking against other types you will get different results.
jmut
Forum Regular
Posts: 945 Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:
Post
by jmut » Mon Feb 05, 2007 1:08 am