|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15340 foreach doesnt reset object arrays
Submitted: 2002-02-02 03:19 UTC Modified: 2002-02-19 15:55 UTC
From: advGraph at regiocom dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.1.1 OS: Windows 2000
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: advGraph at regiocom dot net
New email:
PHP Version: OS:


 [2002-02-02 03:19 UTC] advGraph at regiocom dot net
Using reset on an array of objects seems to alter the array counters of the object's arrays, even though foreach is not dealing with that array.  Then, as foreach is supposed to, it doesnt reset them.


class child{
  var $items = array("A1", "A2", "A3");
$arr=array(new child, new child, new child);
print "step1<br>";
print sizeof($arr)."<br>";
foreach($arr as $v)
  print $v->items[0]."<br>";  // Three A1 printed
print "<hr>step2<br>";
print sizeof($arr)."<br>";
foreach($arr as $v)
  print $v[1]."<br>";  // No A1 printed


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-19 15:48 UTC]
Your code is wrong.
Printing $v->items[0] will always give you 'A1' because you print the array-index 0 which is 'A1'.

The second foreach loop can not print 'A1' because you are printing the object itself and not the items array inside the object.
 [2002-02-19 15:55 UTC]
marking bogus -> user error
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 07:03:37 2021 UTC