#27964 [Opn->Ver]: foreach() + @ + with references broken

From: Date: Mon, 12 Apr 2004 23:41:34 +0000
Subject: #27964 [Opn->Ver]: foreach() + @ + with references broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57992@lists.php.net to get a copy of this message
 ID:               27964
 Updated by:       sniper@php.net
 Reported By:      jeff at opendbms dot com
-Status:           Open
+Status:           Verified
 Bug Type:         Zend Engine 2 problem
-Operating System: Linux
+Operating System: *
-PHP Version:      5.0.0RC1
+PHP Version:      5CVS-2004-04-13
 New Comment:

# php -r '$array = array(); foreach(@$array as $key => &$value) {}'
Fatal error: Cannot create references to elements of a temporary array
expression in Command line code on line 1

(remove @ -> no error)

# php -r '$array = array(); foreach($array as &$value) {}'
Fatal error: Key element cannot be a reference in Command line code on
line 1

# php -r '$array = array(); foreach(@$array as &$value) {}'
PHP Parse error:  parse error, expecting T_STRING' or T_VARIABLE' or
`'$'' in Command line code on line 1



Previous Comments:
------------------------------------------------------------------------

[2004-04-12 14:32:21] jeff at opendbms dot com

Description:
------------
When I run this code:

foreach (@$formErrors as &$formError) {

I get this:

parse error, unexpected '&', expecting T_STRING or T_VARIABLE or '$' 

Something about using both the @ and the & in the same foreach loop. It
works with either one alone, just not both.

Reproduce code:
---------------
use the foreach on a non-existant array with references, and the @
statement modifier.

Expected result:
----------------
Should skip the foreach loop.

Actual result:
--------------
Doesn't work.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27964&edit=1


Thread (4 messages)

« previous php.bugs (#57992) next »