From: stitch at tuks dot co dot za
Operating system: Windows XP & Linux
PHP version: 4.3.4
PHP Bug Type: Variables related
Bug description: Variable with value 0 is not evaluated correctly within if statement
Description:
------------
When i use foreach to go through an array, and use an if statement to
evaluate the $key, it enters into the if statement incorrectly when $key =
0, even though the if statement reads 'if ($key == "test")'
It is not supposed to enter when $key = 0, but as the Actual result shows,
it does.
This does not happen even when $key = 1, tho.
I have tested this on both PHP 4.3.4 and PHP 4.0.1
Thank you very much, keep up the good work.
Reproduce code:
---------------
<?
$the_array["aap"] = array("figure"=> "circle", "colour"=>"blue");
$the_array[] = array("figure" => "triangle", "colour"=>"red");
$the_array["test"] = array ("figure" => "sqaure", "colour"=>"neon");
foreach ( $the_array as $key => $value){
if ($key == "test") {
echo "\$key = $key\n";
echo "A ". $value["colour"]. " " . $value["figure"]."\n";
}
}
?>
Expected result:
----------------
The following output in text:
$key = test
A neon sqaure
Actual result:
--------------
The following output in text:
$key = 0
A red triangle
$key = test
A neon sqaure
--
Edit bug report at http://bugs.php.net/?id=27066&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27066&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27066&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27066&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27066&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27066&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27066&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27066&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27066&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27066&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27066&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27066&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27066&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27066&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27066&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27066&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27066&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27066&r=float