|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
12 + 8 = ?
Subscribe to this entry?

 [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 Oct 15 20:03:45 2021 UTC