php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch php-5.4.0svn-add-foreach-list-support.patch for Scripting Engine problem Bug #10203

Patch version 2011-07-06 12:15 UTC

Return to Bug #10203 | Download this patch
Patch Revisions:

Developer: laruence@php.net

Index: Zend/zend_compile.c
===================================================================
--- Zend/zend_compile.c	(revision 313002)
+++ Zend/zend_compile.c	(working copy)
@@ -5836,7 +5836,7 @@
 	znode dummy, value_node;
 	zend_bool assign_by_ref=0;
 
-	opline = &CG(active_op_array)->opcodes[as_token->u.op.	opline_num];
+	opline = &CG(active_op_array)->opcodes[as_token->u.op.opline_num];
 	if (key->op_type != IS_UNUSED) {
 		znode *tmp;
 
@@ -5849,8 +5849,13 @@
 		opline->extended_value |= ZEND_FE_FETCH_WITH_KEY;
 	}
 
-	if ((key->op_type != IS_UNUSED) && (key->EA & ZEND_PARSED_REFERENCE_VARIABLE)) {
-		zend_error(E_COMPILE_ERROR, "Key element cannot be a reference");
+	if ((key->op_type != IS_UNUSED)) {
+        if (key->EA & ZEND_PARSED_REFERENCE_VARIABLE) {
+		    zend_error(E_COMPILE_ERROR, "Key element cannot be a reference");
+        }
+        if (key->EA & ZEND_PARSED_LIST) {
+		    zend_error(E_COMPILE_ERROR, "Key element cannot be a list expression");
+        }
 	}
 
 	if (value->EA & ZEND_PARSED_REFERENCE_VARIABLE) {
@@ -5885,16 +5890,20 @@
 	}
 
 	GET_NODE(&value_node, opline->result);
+    if (value->EA & ZEND_PARSED_LIST) {
+        zend_do_list_end(&dummy, &value_node TSRMLS_CC);
+        zend_do_free(&dummy TSRMLS_CC);
+    } else {
+        if (assign_by_ref) {
+            zend_do_end_variable_parse(value, BP_VAR_W, 0 TSRMLS_CC);
+            /* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */
+            zend_do_assign_ref(NULL, value, &value_node TSRMLS_CC);
+        } else {
+            zend_do_assign(&dummy, value, &value_node TSRMLS_CC);
+            zend_do_free(&dummy TSRMLS_CC);
+        }
+    }
 
-	if (assign_by_ref) {
-		zend_do_end_variable_parse(value, BP_VAR_W, 0 TSRMLS_CC);
-		/* Mark FE_FETCH as IS_VAR as it holds the data directly as a value */
-		zend_do_assign_ref(NULL, value, &value_node TSRMLS_CC);
-	} else {
-		zend_do_assign(&dummy, value, &value_node TSRMLS_CC);
-		zend_do_free(&dummy TSRMLS_CC);
-	}
-
 	if (key->op_type != IS_UNUSED) {
 		znode key_node;
 
Index: Zend/zend_compile.h
===================================================================
--- Zend/zend_compile.h	(revision 313002)
+++ Zend/zend_compile.h	(working copy)
@@ -718,6 +718,7 @@
 #define ZEND_PARSED_VARIABLE			(1<<4)
 #define ZEND_PARSED_REFERENCE_VARIABLE	(1<<5)
 #define ZEND_PARSED_NEW					(1<<6)
+#define ZEND_PARSED_LIST					(1<<7)
 
 
 /* unset types */
Index: Zend/zend_language_parser.y
===================================================================
--- Zend/zend_language_parser.y	(revision 313002)
+++ Zend/zend_language_parser.y	(working copy)
@@ -308,7 +308,7 @@
 		foreach_statement { zend_do_foreach_end(&$1, &$4 TSRMLS_CC); }
 	|	T_FOREACH '(' expr_without_variable T_AS
 		{ zend_do_foreach_begin(&$1, &$2, &$3, &$4, 0 TSRMLS_CC); }
-		variable foreach_optional_arg ')' { zend_check_writable_variable(&$6); zend_do_foreach_cont(&$1, &$2, &$4, &$6, &$7 TSRMLS_CC); }
+		foreach_variable foreach_optional_arg ')' { zend_check_writable_variable(&$6); zend_do_foreach_cont(&$1, &$2, &$4, &$6, &$7 TSRMLS_CC); }
 		foreach_statement { zend_do_foreach_end(&$1, &$4 TSRMLS_CC); }
 	|	T_DECLARE { $1.u.op.opline_num = get_next_op_number(CG(active_op_array)); zend_do_declare_begin(TSRMLS_C); } '(' declare_list ')' declare_statement { zend_do_declare_end(&$1 TSRMLS_CC); }
 	|	';'		/* empty statement */
@@ -424,6 +424,7 @@
 foreach_variable:
 		variable			{ zend_check_writable_variable(&$1); $$ = $1; }
 	|	'&' variable		{ zend_check_writable_variable(&$2); $$ = $2;  $$.EA |= ZEND_PARSED_REFERENCE_VARIABLE; }
+	|	T_LIST '('		{ zend_do_list_init(TSRMLS_C); } assignment_list ')' { $$ = $1;$$.EA |= ZEND_PARSED_LIST; }
 ;
 
 for_statement:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC