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

From: Date: Mon, 23 Apr 2007 04:38:57 +0000
Subject: #41169 [Opn]: foreach() on empty array causes key to be created
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111792@lists.php.net to get a copy of this message
ID: 41169 User updated by: mobile-g at softhome dot net Reported By: mobile-g at softhome dot net Status: Open Bug Type: Unknown/Other Function Operating System: Red Hat PHP Version: 4.4.6 New Comment: var $myArray = Array(); foreach($this -> mayArray['value'] as $value){ $myVAR += $value; //changed this line } actually it isn't asssigning to itself... this version is correct. Previous Comments: ------------------------------------------------------------------------ [2007-04-23 04:36:57] mobile-g at softhome dot net 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 this bug report at http://bugs.php.net/?id=41169&edit=1

« previous php.bugs (#111792) next »