From: tbielawa at definitivellc dot com
Operating system: linix 2.6.6
PHP version: 5.1.2
PHP Bug Type: Arrays related
Bug description: 0 as second key in array causes false equality in foreach
Description:
------------
combination of array with zero as the second key and foreach loop is
causing false equality. See simple example below...
./configure --with-apxs=/work/st/daemons/apache/bin/apxs --disable-libxml
--prefix=/work/st/daemons/php --with-zlib --disable-dom
--disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter
--without-pear
Reproduce code:
---------------
<?php /*>*/;
$value = 'T';
$options = array('T' => 'TBD', '0' => 'Level 0',
'1' => 'Level 1', '2' => 'Level 2'
);
var_dump($options);
echo '<br>';
foreach($options as $val => $txt) {
if($value == $val) {
echo "$value == $val<br>" ;
}
}
?>
Expected result:
----------------
I expect to ONLY see T == T.
Actual result:
--------------
result is:
T == T
T == 0
--
Edit bug report at http://bugs.php.net/?id=36329&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36329&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36329&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36329&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36329&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36329&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36329&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36329&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36329&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36329&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36329&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36329&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36329&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36329&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36329&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36329&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36329&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36329&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36329&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36329&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36329&r=mysqlcfg