note 20135 deleted from control-structures.foreach by alindeman

From: Date: Sat, 23 Mar 2002 20:41:31 +0000
Subject: note 20135 deleted from control-structures.foreach by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28129@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.

« previous php.notes (#28129) next »