ID:               15340
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Closed
 Bug Type:         Arrays related
 Operating System: Windows 2000
 PHP Version:      4.1.1
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2002-02-02 03:19:17] [EMAIL PROTECTED]

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



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=15340&edit=1

Reply via email to