summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2007-05-02 13:21:55 +0000
committerDmitry Stogov <dmitry@php.net>2007-05-02 13:21:55 +0000
commit688cc5039ac5e63eff514496e0438e13811d4dbd (patch)
treee52712ae3677fcca9e7718399d76ba535b07c433 /Zend
parentc327dec913b3511bf64996c21a38fe9944ccb50d (diff)
downloadphp-git-688cc5039ac5e63eff514496e0438e13811d4dbd.tar.gz
Fixed altering $this via argument named "this"
Diffstat (limited to 'Zend')
-rwxr-xr-xZend/tests/bug41117_1.phpt14
-rw-r--r--Zend/zend_compile.c11
2 files changed, 24 insertions, 1 deletions
diff --git a/Zend/tests/bug41117_1.phpt b/Zend/tests/bug41117_1.phpt
new file mode 100755
index 0000000000..f555b637ad
--- /dev/null
+++ b/Zend/tests/bug41117_1.phpt
@@ -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
+
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 3d4afa8f81..c660d83cf4 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1265,9 +1265,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_STRLEN(varname->u.constant) == sizeof("this")-1) &&
+ (memcmp(Z_STRVAL(varname->u.constant), "this", sizeof("this")) == 0)) {
+ 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;