]> granicus.if.org Git - php/commitdiff
Fixed altering $this via argument named "this"
authorDmitry Stogov <dmitry@php.net>
Wed, 2 May 2007 13:22:15 +0000 (13:22 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 2 May 2007 13:22:15 +0000 (13:22 +0000)
Zend/tests/bug41117_1.phpt [new file with mode: 0755]
Zend/zend_compile.c

diff --git a/Zend/tests/bug41117_1.phpt b/Zend/tests/bug41117_1.phpt
new file mode 100755 (executable)
index 0000000..f555b63
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #41117 (Altering $this via argument)
+--FILE--
+<?php
+class foo {
+  function __construct($this) {
+    echo $this."\n";
+  }
+}
+$obj = new foo("Hello world");
+?>
+--EXPECTF--
+Fatal error: Cannot re-assign $this in %sbug41117_1.php on line 3
+
index 40da0a4c58669058c418a4c3a8cc7c459dce8069..f758e4cdb02a14cab0e962e7e1caa3400ae1ecee 100644 (file)
@@ -1342,9 +1342,18 @@ void zend_do_end_function_declaration(znode *function_token TSRMLS_DC)
 
 void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initialization, znode *class_type, znode *varname, zend_uchar pass_by_reference TSRMLS_DC)
 {
-       zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
+       zend_op *opline;
        zend_arg_info *cur_arg_info;
 
+       if (CG(active_op_array)->scope &&
+               ((CG(active_op_array)->fn_flags & ZEND_ACC_STATIC) == 0) &&
+           (Z_TYPE(varname->u.constant) == IS_STRING || Z_TYPE(varname->u.constant) == IS_UNICODE) &&
+           Z_UNILEN(varname->u.constant) == (sizeof("this")-1) &&
+           ZEND_U_EQUAL(Z_TYPE(varname->u.constant), Z_UNIVAL(varname->u.constant), Z_UNILEN(varname->u.constant), "this", sizeof("this")-1)) {
+               zend_error(E_COMPILE_ERROR, "Cannot re-assign $this");
+       }
+
+       opline = get_next_op(CG(active_op_array) TSRMLS_CC);
        CG(active_op_array)->num_args++;
        opline->opcode = op;
        opline->result = *var;