]> granicus.if.org Git - php/commitdiff
Fixed bug #34358 (Fatal error: Cannot re-assign $this)
authorDmitry Stogov <dmitry@php.net>
Mon, 3 Oct 2005 08:21:20 +0000 (08:21 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 3 Oct 2005 08:21:20 +0000 (08:21 +0000)
Zend/tests/bug34358.phpt [new file with mode: 0755]
Zend/zend_compile.c

diff --git a/Zend/tests/bug34358.phpt b/Zend/tests/bug34358.phpt
new file mode 100755 (executable)
index 0000000..b9c6565
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #34358 (Fatal error: Cannot re-assign $this(again))
+--FILE--
+<?php
+class foo {
+  function bar() {
+    $ref = &$this;
+  }
+}
+$x = new foo();
+$x->bar();
+echo "ok\n";
+?>
+--EXPECT--
+ok
index 2a19b0398f5dfd839365bdc8ef2ba1512e738e59..866ebe205d2bc471998bc97218cea2f4e6c1d7bf 100644 (file)
@@ -596,7 +596,8 @@ void zend_do_assign(znode *result, znode *variable, znode *value TSRMLS_DC)
                        *result = last_op->result;
                        return;
                } else {
-                       if (opline_is_fetch_this(last_op TSRMLS_CC)) {
+                       if (variable->op_type == IS_VAR &&
+                           opline_is_fetch_this(last_op TSRMLS_CC)) {
                                zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
                        }
                }
@@ -626,7 +627,8 @@ void zend_do_assign_ref(znode *result, znode *lvar, znode *rvar TSRMLS_DC)
        if (last_op_number > 0) {
                zend_op *last_op = &CG(active_op_array)->opcodes[last_op_number-1];
 
-               if (opline_is_fetch_this(last_op TSRMLS_CC)) {
+               if (lvar->op_type == IS_VAR &&
+                   opline_is_fetch_this(last_op TSRMLS_CC)) {
                        zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
                }
        }