PHP 4.0 Bug #9722 Updated: foreach() operates on a copy of an object

From: Date: Tue, 13 Mar 2001 21:13:44 +0000
Subject: PHP 4.0 Bug #9722 Updated: foreach() operates on a copy of an object
Groups: php.dev 
Request: Send a blank email to php-dev+get-48838@lists.php.net to get a copy of this message
ID: 9722 Updated by: sniper Reported By: johanp@aditus.nu Old-Status: Open Status: Closed Bug Type: Class/Object related Assigned To: Comments: Please read the manual: http://www.php.net/manual/en/control-structures.foreach.php "Note: Also note that foreach operates on a copy of the specified array, not the array itself, therefore the array pointer is not modified like with the each construct." --Jani Previous Comments: --------------------------------------------------------------------------- [2001-03-13 05:09:29] johanp@aditus.nu The following two array looping statements are not equal (Assuming Update() updates some instance variables in the object) foreach( $objs as $o ) $o->Update() and for($i=0; $i<count($objs); ++$i) $objs[$i]->Update(); In the first case the Update() method will change an anonymous copy of the object in the array while in the second case the update will work on the object in the array. Hence any changes that Update() might do will in the first case not be done for the objects in the array. Not sure if this is a genuine bug or just a consequence of the copying semantics for objects in PHP. --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=9722&edit=2

« previous php.dev (#48838) next »