Skip to content

Commit 5feeda0

Browse files
committed
Fix FETCH_THIS result type
1 parent 4d2cc20 commit 5feeda0

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ static bool this_guaranteed_exists(void) /* {{{ */
30223022
static zend_op *zend_compile_simple_var(znode *result, const zend_ast *ast, uint32_t type, bool delayed) /* {{{ */
30233023
{
30243024
if (is_this_fetch(ast)) {
3025-
zend_op *opline = zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
3025+
zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_THIS, NULL, NULL);
30263026
if ((type == BP_VAR_R) || (type == BP_VAR_IS)) {
30273027
opline->result_type = IS_TMP_VAR;
30283028
result->op_type = IS_TMP_VAR;
@@ -3155,7 +3155,7 @@ 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+
zend_emit_op_tmp(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
31593159
}
31603160
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
31613161

@@ -3889,7 +3889,7 @@ static uint32_t zend_compile_args(
38893889
if (arg->kind == ZEND_AST_VAR) {
38903890
CG(zend_lineno) = zend_ast_get_lineno(ast);
38913891
if (is_this_fetch(arg)) {
3892-
zend_emit_op(&arg_node, ZEND_FETCH_THIS, NULL, NULL);
3892+
zend_emit_op_tmp(&arg_node, ZEND_FETCH_THIS, NULL, NULL);
38933893
opcode = ZEND_SEND_VAR_EX;
38943894
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
38953895
break;
@@ -5379,7 +5379,7 @@ static void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type
53795379
if (this_guaranteed_exists()) {
53805380
obj_node.op_type = IS_UNUSED;
53815381
} else {
5382-
zend_emit_op(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
5382+
zend_emit_op_tmp(&obj_node, ZEND_FETCH_THIS, NULL, NULL);
53835383
}
53845384
CG(active_op_array)->fn_flags |= ZEND_ACC_USES_THIS;
53855385

0 commit comments

Comments
 (0)