PHP Comparison Issues ... 0 equates to 'D'
Bug #928550 reported by
LaChild
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
php5 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Hello,
Using "PHP 5.3.6-13ubuntu3.3 with Suhosin-Patch (cli)" I noticed the following bug. Apparently the (integer) 0 equates to the same thing as (string) 'D'
Example:
-------
<?php
$test = 'D';
if ($test == 'D')
echo 'true'; // Echos true
$testZero = 0;
if ($testZero == 'D')
echo 'true'; //Also echos true
-------
Both equate to "true" but the 0 should not.
Thanks,
LaChild
To post a comment you must log in.
Thanks for taking the time to report this issue and help improve Ubuntu. While from a programmer's perspective, it's unexpected behavior; however, it is correct as documented at:
http:// php.net/ manual/ en/language. operators. comparison. php
What's happening is that when comparing a string to a number, php is converting the string (in this case 'D') to a number. Because 'D' isn't a (base 10) number, it treats it as the number 0. And thus 0 == 0 returns true.
Please feel free to report any additional issues you come across. Thanks again!