|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14152 foreach() can create objects with blank property names
Submitted: 2001-11-20 13:22 UTC Modified: 2002-01-15 07:19 UTC
From: basil dot hussain at kodakweddings dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.0.5 OS: Linux 2.2.16-enterprise
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: basil dot hussain at kodakweddings dot com
New email:
PHP Version: OS:


 [2001-11-20 13:22 UTC] basil dot hussain at kodakweddings dot 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)!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-22 18:45 UTC]
Much easier to reproduce by:


Foreach loop should of course read

foreach($myarray as $key=>$value)

 [2002-01-15 07:19 UTC]
Bogus, user error.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 13:01:29 2024 UTC