PHP 4.0 Bug #9722: foreach() operates on a copy of an object
| From: | johanp at aditus dot nu | Date: | Tue, 13 Mar 2001 10:09:29 +0000 |
| Subject: | PHP 4.0 Bug #9722: foreach() operates on a copy of an object | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-48795@lists.php.net to get a copy of this message | ||
From: johanp@aditus.nu
Operating system: Linux 2.2.16
PHP version: 4.0.4pl1
PHP Bug Type: Class/Object related
Bug description: foreach() operates on a copy of an object
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.
--
Edit Bug report at: http://bugs.php.net/?id=9722&edit=1