#42384 [Bgs->Opn]: Foreach Referencing Problem
| From: | jw at coffeecup dot com | Date: | Wed, 22 Aug 2007 16:45:41 +0000 |
| Subject: | #42384 [Bgs->Opn]: Foreach Referencing Problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116490@lists.php.net to get a copy of this message | ||
ID: 42384
User updated by: jw at coffeecup dot com
Reported By: jw at coffeecup dot com
-Status: Bogus
+Status: Open
Bug Type: Scripting Engine problem
Operating System: OS X
PHP Version: 5.2.3
New Comment:
Then shouldn't I get this error:
Fatal error: Cannot create references to elements of a temporary array
expression
Previous Comments:
------------------------------------------------------------------------
[2007-08-22 16:38:24] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The value created by (array)$arr is a temporary variable which can\'t
be referenced.
------------------------------------------------------------------------
[2007-08-22 16:21:55] jw at coffeecup dot com
Description:
------------
I get a syntax error when I cast the array_expression portion of a
foreach loop to an array while using the & operator on the value
portion.
Reproduce code:
---------------
$arr = array(1, 2, 3, 4);
foreach ((array)$arr as &$value) {
$value = $value * 2;
}
print_r($arr);
Expected result:
----------------
Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
)
Actual result:
--------------
Parse error: syntax error, unexpected '&', expecting T_STRING or
T_VARIABLE or '$'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42384&edit=1