Re: Bug #15663 Updated: add foreach reference values
| From: | Yasuo Ohgaki | Date: | Fri, 22 Feb 2002 01:29:16 +0000 |
| Subject: | Re: Bug #15663 Updated: add foreach reference values | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-80286@lists.php.net to get a copy of this message | ||
yohgaki@php.net wrote:
I think reference support is in TODO. Therefore, I guess it's better to be closed since object part is already done. Any comments? -- Yasuo OhgakiID: 15663Updated by: yohgaki@php.net Reported By: greg@mtechsolutions.ca-Status: Open +Status: Closed Bug Type: Feature/Change RequestPHP Version: 4.1.1 New Comment: This bug has been fixed in CVS. ZendEngine2 uses handle for object.
Previous Comments: ------------------------------------------------------------------------ [2002-02-21 17:20:05] mfischer@php.net Objects are bad examples as they will completely change how they behave in ZE2. However, it is true for normal arrays and it's in the TODO list of PHP: "Zend ------ Yasuo Ohgaki Please CC me when you reply to news/list messages. Do not reply only to me :)* allow foreach ($array as $k => &$val) syntax. right now we cannottraverse an array without copying each element."------------------------------------------------------------------------ [2002-02-21 12:34:00] greg@mtechsolutions.ca Just a small request that could be fairly useful. Say you have an array of objects, $objects. Right now, doing: foreach ($objects as $obj) { $obj->something(); } will create a copy of each object (using unnecessary memory) and call something() on the copy, not the actual object (which is bad if it's a mutator function of that class). The best way to do it now is to do: foreach (array_keys($objects) as $key) { $objects[$key]->something(); } but it would be very cool if php had the syntax: foreach ($objects as &$obj) where it would create $obj as a reference to each object. thanks ------------------------------------------------------------------------