Re: Bug #3922: == bug

From: Date: Sat, 25 Mar 2000 07:55:51 +0000
Subject: Re: Bug #3922: == bug
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-17210@lists.php.net to get a copy of this message
: the following program IMO misbehaves (tested on php 3.0.12 and php-4.0b4pl1): : <? : $var = 0; : if($var == 'N/A') : echo "PHP claims \$var is 'N/A', actual \$var's value is $var\n"; : else : echo "this version of PHP is ok\n"; : ?> : : note that when the value of $var is non-zero all is okay. i guess that's a bug and not a feature. This is not a bug, $var is numeric, and the right hand side is converted to numeric as well, which evaluates to 0. This is what PHP does: if ( 0 == 0 ) // true! But if $var != 0, then it would behave like: if ( 10 == 0 ) // false! Wrap $var in double quotes if you want it to behave as a string and not numeric. Enjoy!

« previous php.dev (#17210) next »