cvs: ZendEngine2 / zend_compile.c /tests bug34467.phpt
| From: | Dmitry Stogov | Date: | Mon, 10 Oct 2005 09:50:20 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c /tests bug34467.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4222@lists.php.net to get a copy of this message | ||
dmitry Mon Oct 10 05:50:20 2005 EDT
Modified files:
/ZendEngine2 zend_compile.c
/ZendEngine2/tests bug34467.phpt
Log:
Fixed bug #34467 (foreach + __get + __set incosistency)
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.665&r2=1.666&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.665 ZendEngine2/zend_compile.c:1.666
--- ZendEngine2/zend_compile.c:1.665 Mon Oct 3 04:21:15 2005
+++ ZendEngine2/zend_compile.c Mon Oct 10 05:50:19 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.665 2005/10/03 08:21:15 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.666 2005/10/10 09:50:19 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -566,40 +566,53 @@
void zend_do_assign(znode *result, znode *variable, znode *value TSRMLS_DC)
{
- int last_op_number = get_next_op_number(CG(active_op_array));
zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
- if (last_op_number > 0) {
- zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number-1];
+ if (variable->op_type == IS_VAR) {
+ int last_op_number = get_next_op_number(CG(active_op_array));
+ int n = 0;
- if (variable->op_type == IS_VAR &&
- last_op->opcode == ZEND_FETCH_OBJ_W &&
- last_op->result.op_type == IS_VAR &&
- last_op->result.u.var == variable->u.var) {
- last_op->opcode = ZEND_ASSIGN_OBJ;
+ while (last_op_number - n > 0) {
+ zend_op *last_op;
+
+ last_op = &CG(active_op_array)->opcodes[last_op_number-n-1];
- zend_do_op_data(opline, value TSRMLS_CC);
- SET_UNUSED(opline->result);
- *result = last_op->result;
- return;
- } else if (variable->op_type == IS_VAR &&
- last_op->opcode == ZEND_FETCH_DIM_W &&
- last_op->result.op_type == IS_VAR &&
- last_op->result.u.var == variable->u.var) {
- last_op->opcode = ZEND_ASSIGN_DIM;
-
- zend_do_op_data(opline, value TSRMLS_CC);
- opline->op2.u.var = get_temporary_variable(CG(active_op_array));
- opline->op2.u.EA.type = 0;
- opline->op2.op_type = IS_VAR;
- SET_UNUSED(opline->result);
- *result = last_op->result;
- return;
- } else {
- if (variable->op_type == IS_VAR &&
- opline_is_fetch_this(last_op TSRMLS_CC)) {
- zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
+ if (last_op->result.op_type == IS_VAR &&
+ last_op->result.u.var == variable->u.var) {
+ if (last_op->opcode == ZEND_FETCH_OBJ_W) {
+ if (n > 0) {
+ *opline = *last_op;
+ MAKE_NOP(last_op);
+ last_op = opline;
+ opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+ }
+ last_op->opcode = ZEND_ASSIGN_OBJ;
+ zend_do_op_data(opline, value TSRMLS_CC);
+ SET_UNUSED(opline->result);
+ *result = last_op->result;
+ return;
+ } else if (last_op->opcode == ZEND_FETCH_DIM_W) {
+ if (n > 0) {
+ *opline = *last_op;
+ MAKE_NOP(last_op);
+ last_op = opline;
+ opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+ }
+ last_op->opcode = ZEND_ASSIGN_DIM;
+ zend_do_op_data(opline, value TSRMLS_CC);
+ opline->op2.u.var = get_temporary_variable(CG(active_op_array));
+ opline->op2.u.EA.type = 0;
+ opline->op2.op_type = IS_VAR;
+ SET_UNUSED(opline->result);
+ *result = last_op->result;
+ return;
+ } else if (opline_is_fetch_this(last_op TSRMLS_CC)) {
+ zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
+ } else {
+ break;
+ }
}
+ n++;
}
}
http://cvs.php.net/diff.php/ZendEngine2/tests/bug34467.phpt?r1=1.1&r2=1.2&ty=u
Index: ZendEngine2/tests/bug34467.phpt
diff -u /dev/null ZendEngine2/tests/bug34467.phpt:1.2
--- /dev/null Mon Oct 10 05:50:20 2005
+++ ZendEngine2/tests/bug34467.phpt Mon Oct 10 05:50:20 2005
@@ -0,0 +1,27 @@
+--TEST--
+Bug #34467 (foreach + __get + __set incosistency)
+--FILE--
+<?php
+class abc {
+ private $arr;
+
+ function __set ($key, $value) {
+ $this->arr[$key] = $value;
+ }
+
+ function __get ($key) {
+ return $this->arr[$key];
+ }
+}
+$abc = new abc();
+foreach (array (1,2,3) as $abc->k => $abc->v) {
+ var_dump($abc->k,$abc->v);
+}
+?>
+--EXPECT--
+int(0)
+int(1)
+int(1)
+int(2)
+int(2)
+int(3)