OK, this one is just plain weird.

I have coded php for years and have never seen this one before, yet it is very simple.

I am working on a component for Joomla, but that shouldn't really matter.

I am getting a variable from the request string with this Joomla function:

$var = mosGetParam( $_REQUEST, 'var', '0' );

All it does is set the var to 0 if it does not exist. I can see in my query string that the $var is set to 0 and when I echo the $var it also returns 0.

Now... here comes the scary part.

When I run an if structure on the $var it always returns true if what I compare it to is a string. Like this

Code PHP:
if ($var == "somestring") {
  echo "var is somestring: ".$var;

But the echo is var is somestring: 0

If i do the following:

Code PHP:
if ($var == "1") {
  echo "var is 1: ".$var;

It fails and does not validate, even though 1 is also a string in this comparison.

What is going on?

I have tried === but that is only for boolean - right? And I still want to know what is going on.

P.S. What I am really trying to do is check a check box if a certain value is "yes" but when the value id 0 and I check for "yes" it still returns true?!?!