]> granicus.if.org Git - php/commitdiff
MFH: Fix indirect reference of $this
authorScott MacVicar <scottmac@php.net>
Fri, 10 Dec 2010 06:34:03 +0000 (06:34 +0000)
committerScott MacVicar <scottmac@php.net>
Fri, 10 Dec 2010 06:34:03 +0000 (06:34 +0000)
NEWS
Zend/tests/indirect_reference_this.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 1073939d73988677d22d3a3ca14704618307456b..5eb9102636e894368e5f212b2855013af317663d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@
 - PDO Oracle driver:
   . Fixed bug #39199 (Cannot load Lob data with more than 4000 bytes on
     ORACLE 10). (spatar at mail dot nnov dot ru)
+    
+- Indirect reference to $this fails to resolve if direct $this is never used
+  in method. (Scott)
 
 09 Dec 2010, PHP 5.3.4
 - Upgraded bundled Sqlite3 to version 3.7.3. (Ilia)
diff --git a/Zend/tests/indirect_reference_this.phpt b/Zend/tests/indirect_reference_this.phpt
new file mode 100644 (file)
index 0000000..05419d6
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Indirect referenced $this
+--FILE--
+<?php
+class X {
+  function f($x){var_dump($$x);}
+}
+$x = new X;
+$x->f("this");
+?>
+--EXPECTF--
+object(X)#%d (0) {
+}
\ No newline at end of file
index 799b77410b371583e3e6833d297efee720889c34..c0150d4c69c6b0431648af2d004b05eba07d975d 100644 (file)
@@ -4351,6 +4351,10 @@ void zend_do_indirect_references(znode *result, const znode *num_references, zno
        }
        zend_do_begin_variable_parse(TSRMLS_C);
        fetch_simple_variable(result, variable, 1 TSRMLS_CC);
+       /* there is a chance someone is accessing $this */
+       if (CG(active_op_array)->scope && CG(active_op_array)->this_var == -1) {
+               CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), estrndup("this", sizeof("this")-1), sizeof("this")-1 TSRMLS_CC);
+       }
 }
 /* }}} */