Bug #15340 Updated: foreach doesnt reset object arrays

From: Date: Tue, 19 Feb 2002 20:55:28 +0000
Subject: Bug #15340 Updated: foreach doesnt reset object arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-612@lists.php.net to get a copy of this message
ID: 15340 Updated by: mrobinso@php.net Reported By: advGraph@regiocom.net -Status: Closed +Status: Bogus Bug Type: Arrays related Operating System: Windows 2000 PHP Version: 4.1.1 New Comment: marking bogus -> user error Previous Comments: ------------------------------------------------------------------------ [2002-02-19 15:48:25] 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-02 03:19:17] advGraph@regiocom.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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=15340&edit=1

« previous php.bugs (#612) next »