php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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.

Example:

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-19 15:48 UTC] cmk@php.net
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] mrobinso@php.net
marking bogus -> user error
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC