#42384 [Opn->Bgs]: Foreach Referencing Problem
| From: | johannes@php.net | Date: | Wed, 22 Aug 2007 16:38:24 +0000 |
| Subject: | #42384 [Opn->Bgs]: Foreach Referencing Problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116488@lists.php.net to get a copy of this message | ||
ID: 42384
Updated by: johannes@php.net
Reported By: jw at coffeecup dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: OS X
PHP Version: 5.2.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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