]> granicus.if.org Git - php/commitdiff
Fixed bug #65911 ($this not usable as static property)
authorbwoebi <bobwei9@hotmail.com>
Wed, 16 Oct 2013 14:04:23 +0000 (16:04 +0200)
committerNikita Popov <nikic@php.net>
Wed, 16 Oct 2013 16:33:14 +0000 (18:33 +0200)
In context of static accesses like classname::$this, the string
"$this" should not be handled like a $this variable, but as an
identifier for a static variable.

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

diff --git a/NEWS b/NEWS
index fcf34c3fb9ec9faad7f28369e71b2e7235fde27d..6c2c6ed13b5aabe00f7c653359afe36b559622b4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2013, PHP 5.4.22
 
+- Core:
+  . Fixed bug #65911 (scope resolution operator - strange behavior with $this).
+    (Bob Weinand)
+
 - CLI server:
   . Fixed bug #65818 (Segfault with built-in webserver and chunked transfer 
     encoding). (Felipe)
diff --git a/Zend/tests/bug65911.phpt b/Zend/tests/bug65911.phpt
new file mode 100644 (file)
index 0000000..b9f37b7
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #65911 (scope resolution operator - strange behavior with $this)
+--FILE--
+<?php
+class A {}
+
+class B
+{
+       public function go()
+       {
+               $this->foo = 'bar';
+               echo A::$this->foo; // should not output 'bar'
+       }
+}
+
+$obj = new B();
+$obj->go();
+?>
+--EXPECTF--
+Fatal error: Access to undeclared static property: A::$this in %s on line %d
index 326d4ef976795e57d4794d701b6cdef4d4aa4faa..10390b04a8df0ad474c50a9d3365d25eb001225e 100644 (file)
@@ -905,6 +905,7 @@ static zend_bool opline_is_fetch_this(const zend_op *opline TSRMLS_DC) /* {{{ */
 {
        if ((opline->opcode == ZEND_FETCH_W) && (opline->op1_type == IS_CONST)
                && (Z_TYPE(CONSTANT(opline->op1.constant)) == IS_STRING)
+               && ((opline->extended_value & ZEND_FETCH_STATIC_MEMBER) != ZEND_FETCH_STATIC_MEMBER)
                && (Z_HASH_P(&CONSTANT(opline->op1.constant)) == THIS_HASHVAL)
                && (Z_STRLEN(CONSTANT(opline->op1.constant)) == (sizeof("this")-1))
                && !memcmp(Z_STRVAL(CONSTANT(opline->op1.constant)), "this", sizeof("this"))) {