Skip to content

Commit 0f72e19

Browse files
committed
Fix FETCH_THIS result type
1 parent 147838a commit 0f72e19

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
@@ -3153,7 +3153,11 @@ static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t
31533153
if (this_guaranteed_exists()) {
31543154
obj_node.op_type = IS_UNUSED;
31553155
} else {
3156-
zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
3156+
opline = zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
3157+
if ((type == BP_VAR_R) || (type == BP_VAR_IS)) {
3158+
opline->result_type = IS_TMP_VAR;
3159+
obj_node.op_type = IS_TMP_VAR;
3160+
}
31573161
}
31583162
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
31593163

@@ -5479,7 +5483,7 @@ static void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type
54795483
if (this_guaranteed_exists()) {
54805484
obj_node.op_type = IS_UNUSED;
54815485
} else {
5482-
zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
5486+
zend_emit_op_tmp(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
54835487
}
54845488
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
54855489

0 commit comments

Comments
 (0)