Bug #14152 Updated: foreach() can create objects with blank property names

From: Date: Tue, 15 Jan 2002 12:19:01 +0000
Subject: Bug #14152 Updated: foreach() can create objects with blank property names
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-77124@lists.php.net to get a copy of this message
ID: 14152 Updated by: lobbin Reported By: basil.hussain@kodakweddings.com Old Status: Open Status: Bogus Bug Type: Class/Object related Operating System: Linux 2.2.16-enterprise PHP Version: 4.0.5 New Comment: Bogus, user error. Previous Comments: ------------------------------------------------------------------------ [2001-11-22 18:45:47] edink@php.net Much easier to reproduce by: $a->$b="c"; Foreach loop should of course read foreach($myarray as $key=>$value) ------------------------------------------------------------------------ [2001-11-20 13:22:53] basil.hussain@kodakweddings.com Using the following code (which someone may do accidentally): $myarray = array("X" => "A", "Y" => "B", "Z" => "C"); foreach($myarray as $key->$value) { ... } causes PHP (on each iteration) to create an object $key with the value of the current array element in a property with a blank name (because $value has just been created, and is therefore empty). The following var_dump() output illustrates: object(stdClass)(1) { [""]=> string(1) "A" } The creation of objects with blank property names seems like it shouldn't be possible (even unintentionally)! ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14152&edit=1

« previous php.dev (#77124) next »