note 20135 added to control-structures.foreach

From: Date: Sat, 23 Mar 2002 15:38:03 +0000
Subject: note 20135 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-28123@lists.php.net to get a copy of this message
if you construct an array of objects (classes), and then loop over them with foreach, and in the loop you MODIFY EACH OBJECT, it may not work as you expect - the original objects in the array are not modified, only the loop variable. As follows: foreach ($obj_arr as $idx => $obj) $obj->member_func(); Now, if member_func() actually modifies the object's internal member variables, those modifications will not be applied to the original objects in the array $obj_arr, but rather to the loop variable $obj (a COPY of the objects from $obj_arr). If anyone knows a workaround, please email me. -- http://www.php.net/manual/en/control-structures.foreach.php http://master.php.net/manage/user-notes.php?action=edit+20135 http://master.php.net/manage/user-notes.php?action=delete+20135 http://master.php.net/manage/user-notes.php?action=reject+20135

« previous php.notes (#28123) next »