Re: Found a PHP bug!!!!!!!!!

From: Date: Mon, 27 Jan 2003 20:49:33 +0000
Subject: Re: Found a PHP bug!!!!!!!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-133293@lists.php.net to get a copy of this message
> Because "8" != 8. "8" (and "08") is a string with the numerals representing > the number eight. It is not the number eight. (think back to basic math, the > difference between a number and a numeral) Actually, "08" is equal to 8 in PHP. PHP will convert the string to an integer and the two will compare as equal. > PHP does some conversions for you automatically but that just saves you from > yourself. (Personally, I wish it wouldn't. People have more trouble > *because* of the automatic conversions than they would if they had to do the > converting themselves.) Someone already posted why the problem was happening, because the numbers were being converted to invalid octal numbers and being set to zero. Run this bit of code for an example: echo "<br>" . ((01 == 1) ? "Match" : "No Match"); echo "<br>" . ((02 == 2) ? "Match" : "No Match"); echo "<br>" . ((03 == 3) ? "Match" : "No Match"); echo "<br>" . ((04 == 4) ? "Match" : "No Match"); echo "<br>" . ((05 == 5) ? "Match" : "No Match"); echo "<br>" . ((06 == 6) ? "Match" : "No Match"); echo "<br>" . ((07 == 7) ? "Match" : "No Match"); echo "<br>" . ((08 == 8) ? "Match" : "No Match"); echo "<br>" . ((09 == 9) ? "Match" : "No Match"); The last two won't match because 08 and 09 are invalid octal numbers, like Kirk Johnson already said. So "08" != 08 and 8 != 08, for example. ---John Holmes...

« previous php.general (#133293) next »