From: iain at workingsoftware dot com dot au
Operating system: FreeBSD 6.1
PHP version: 5.2.0
PHP Bug Type: Class/Object related
Bug description: Comparing zero & string values in boolean comparison has
unexpected behaviour
Description:
------------
if you have a variable with the value 0 assigned to it and do a comparison
with a non-integer then the non-integer value is cast to an int with
unexpected results. it behaves differently when comparing a non-zero
integer.
Reproduce code:
---------------
put this in test.php and run php -f test.php:
<?php
$zero = 0;
$one = 1;
if($zero == 'SOME STRING')
echo("0 does equal 'SOME STRING'\n");
else
echo("0 does not equal 'SOME STRING'\n");
if($one == 'SOME STRING')
echo("1 does equal 'SOME STRING'\n");
else
echo("1 does not equal 'SOME STRING'\n");
?>
Expected result:
----------------
0 does not equal 'SOME STRING'
1 does not equal 'SOME STRING'
Actual result:
--------------
0 does equal 'SOME STRING'
1 does not equal 'SOME STRING'
--
Edit bug report at http://bugs.php.net/?id=39579&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39579&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39579&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39579&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39579&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39579&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39579&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39579&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39579&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39579&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39579&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39579&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39579&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39579&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39579&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39579&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39579&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39579&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39579&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39579&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39579&r=mysqlcfg