]> granicus.if.org Git - php/commitdiff
Fix bug #71737
authorNikita Popov <nikic@php.net>
Wed, 20 Apr 2016 16:37:23 +0000 (18:37 +0200)
committerNikita Popov <nikic@php.net>
Wed, 20 Apr 2016 16:38:40 +0000 (18:38 +0200)
Also improve the error message for $this used in parameters.

NEWS
Zend/tests/bug41117_1.phpt
Zend/tests/bug71737.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 69155799a04d9f4df0b43aaac4bd9738e2bd79d3..93ca10836ba554b9bfb8175850de775f14afa9a4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
     (Nikita Nefedov)
   . Fixed bug #72038 (Function calls with values to a by-ref parameter don't
     always throw a notice). (Bob)
+  . Fixed bug #71737 (Memory leak in closure with parameter named $this).
+    (Nikita)
 
 - OCI8:
   . Fixed bug #71600 (oci_fetch_all segfaults when selecting more than eight
index f555b637ad80a64ec1ca91f91d70cbecb522f79e..a612f07fed41333366266b7b5cc99e591efe9b10 100644 (file)
@@ -10,5 +10,4 @@ class foo {
 $obj = new foo("Hello world");
 ?>
 --EXPECTF--
-Fatal error: Cannot re-assign $this in %sbug41117_1.php on line 3
-
+Fatal error: Cannot use $this as parameter in %s on line %d
diff --git a/Zend/tests/bug71737.phpt b/Zend/tests/bug71737.phpt
new file mode 100644 (file)
index 0000000..b44de8e
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #71737: Memory leak in closure with parameter named $this
+--FILE--
+<?php
+
+class Test {
+    public function method() {
+        return function($this) {};
+    }
+}
+
+(new Test)->method()(new stdClass);
+
+?>
+--EXPECTF--
+Fatal error: Cannot use $this as parameter in %s on line %d
index 13e774eaba86da48d4823d5359d214257b4ccf4a..89fd0e520ec117df2b9cc36288531e2bef36d851 100644 (file)
@@ -4484,8 +4484,9 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
                        zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
                                ZSTR_VAL(name));
                } else if (zend_string_equals_literal(name, "this")) {
-                       if (op_array->scope && (op_array->fn_flags & ZEND_ACC_STATIC) == 0) {
-                               zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
+                       if ((op_array->scope || (op_array->fn_flags & ZEND_ACC_CLOSURE))
+                                       && (op_array->fn_flags & ZEND_ACC_STATIC) == 0) {
+                               zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as parameter");
                        }
                        op_array->this_var = var_node.u.op.var;
                }