Skip to content

Commit 12ed5ae

Browse files
committed
Fix FETCH_THIS result type
1 parent 4d2cc20 commit 12ed5ae

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Zend/tests/gh20628.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$this->bar();

Zend/tests/gh20628.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Invalid opcode for method call with FETCH_THIS
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public function bar() {
8+
var_dump($this, __METHOD__);
9+
}
10+
11+
public function test() {
12+
require __DIR__ . '/gh20628.inc';
13+
}
14+
}
15+
16+
(new Foo)->test();
17+
18+
?>
19+
--EXPECTF--
20+
object(Foo)#%d (0) {
21+
}
22+
string(8) "Foo::bar"

Zend/zend_compile.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,11 @@ static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t
31553155
if (this_guaranteed_exists()) {
31563156
obj_node.op_type = IS_UNUSED;
31573157
} else {
3158-
zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
3158+
opline = zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
3159+
if ((type == BP_VAR_R) || (type == BP_VAR_IS)) {
3160+
opline->result_type = IS_TMP_VAR;
3161+
obj_node.op_type = IS_TMP_VAR;
3162+
}
31593163
}
31603164
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
31613165

@@ -5379,7 +5383,7 @@ static void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type
53795383
if (this_guaranteed_exists()) {
53805384
obj_node.op_type = IS_UNUSED;
53815385
} else {
5382-
zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
5386+
zend_emit_op_tmp(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
53835387
}
53845388
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
53855389

0 commit comments

Comments
 (0)