#41169 [NEW]: foreach() on empty array causes key to be created

From: Date: Mon, 23 Apr 2007 04:36:57 +0000
Subject: #41169 [NEW]: foreach() on empty array causes key to be created
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111791@lists.php.net to get a copy of this message
From: mobile-g at softhome dot net Operating system: Red Hat PHP version: 4.4.6 PHP Bug Type: Unknown/Other Function Bug description: foreach() on empty array causes key to be created Description: ------------ running a foreach loop on an empty array causes the test key to be created. Note this code has been pulled from a class, I have kept this structure in case that has relevance. Reproduce code: --------------- var $myArray = Array(); foreach($this -> mayArray['value'] as $value){ $myArray += $value; } Expected result: ---------------- Ideally the loop wouldn't run, or would error when trying to locate a none existant key. Actual result: -------------- myArray() has an empty key called "value" added to it. -- Edit bug report at http://bugs.php.net/?id=41169&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41169&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41169&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41169&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41169&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41169&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41169&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41169&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41169&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41169&r=support Expected behavior: http://bugs.php.net/fix.php?id=41169&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41169&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41169&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41169&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41169&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41169&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41169&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41169&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41169&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41169&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41169&r=mysqlcfg

« previous php.bugs (#111791) next »