[solved]is 0 equal to false

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

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

[solved]is 0 equal to false

Post 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?
Last edited by dull1554 on Wed Jan 19, 2005 9:56 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yes in a boolean sense. No in strict typing.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

thankyou:)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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 :)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 :)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i prooved him wrong and got a 100 ont he test :lol:

thanks for the help guys.....
Post Reply