Page 1 of 1
[solved]is 0 equal to false
Posted: Wed Jan 19, 2005 9:49 am
by dull1554
im arguing with a teacher as to a question on a test, he had a function that returned 0 or false, it acctually returns 0, but that is false
what do u guys think
is 0 equal to false?
Posted: Wed Jan 19, 2005 9:52 am
by feyd
Yes in a boolean sense. No in strict typing.
Posted: Wed Jan 19, 2005 9:53 am
by dull1554
thankyou:)
Posted: Wed Jan 19, 2005 9:58 am
by pickle
Well, in PHP it *kind of* is. A they will evaluate true using a "==" comparitor, which in most cases what is used. However, using "===" will NOT work, as "===" requires the type of the variables being compared must also be the same
Show him this:
Code: Select all
if(0 == false)
{
echo "Yep, they match";
}
That should convince him

Posted: Wed Jan 19, 2005 10:27 am
by timvw
the problem lies here: do you (or the teacher) consider php as a strong or a weak typed language?
weak -> 0 equals false
strong -> 0 does not equal false
probably your teacher did not specify that.. so there is at least a shortcoming/lack of explanation from his behalf

Posted: Wed Jan 19, 2005 8:02 pm
by dull1554
i prooved him wrong and got a 100 ont he test
thanks for the help guys.....