Skip to content

Commit 4c0bb6d

Browse files
bwoebinikic
authored andcommitted
Fixed bug #65911 ($this not usable as static property)
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.
1 parent b0a3600 commit 4c0bb6d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2013, PHP 5.4.22
44

5+
- Core:
6+
. Fixed bug #65911 (scope resolution operator - strange behavior with $this).
7+
(Bob Weinand)
8+
59
- CLI server:
610
. Fixed bug #65818 (Segfault with built-in webserver and chunked transfer
711
encoding). (Felipe)

Zend/tests/bug65911.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #65911 (scope resolution operator - strange behavior with $this)
3+
--FILE--
4+
<?php
5+
class A {}
6+
7+
class B
8+
{
9+
public function go()
10+
{
11+
$this->foo = 'bar';
12+
echo A::$this->foo; // should not output 'bar'
13+
}
14+
}
15+
16+
$obj = new B();
17+
$obj->go();
18+
?>
19+
--EXPECTF--
20+
Fatal error: Access to undeclared static property: A::$this in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ static zend_bool opline_is_fetch_this(const zend_op *opline TSRMLS_DC) /* {{{ */
905905
{
906906
if ((opline->opcode == ZEND_FETCH_W) && (opline->op1_type == IS_CONST)
907907
&& (Z_TYPE(CONSTANT(opline->op1.constant)) == IS_STRING)
908+
&& ((opline->extended_value & ZEND_FETCH_STATIC_MEMBER) != ZEND_FETCH_STATIC_MEMBER)
908909
&& (Z_HASH_P(&CONSTANT(opline->op1.constant)) == THIS_HASHVAL)
909910
&& (Z_STRLEN(CONSTANT(opline->op1.constant)) == (sizeof("this")-1))
910911
&& !memcmp(Z_STRVAL(CONSTANT(opline->op1.constant)), "this", sizeof("this"))) {

0 commit comments

Comments
 (0)