Skip to content

Commit 03f41f9

Browse files
committed
Prevent op_array->this_var setting when method uses auto globals
1 parent 18cd4b1 commit 03f41f9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Zend/zend_compile.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,14 +2164,6 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
21642164
znode name_node;
21652165
zend_op *opline;
21662166

2167-
/* there is a chance someone is accessing $this */
2168-
if (ast->kind != ZEND_AST_ZVAL
2169-
&& CG(active_op_array)->scope && CG(active_op_array)->this_var == (uint32_t)-1
2170-
) {
2171-
zend_string *key = zend_string_init("this", sizeof("this") - 1, 0);
2172-
CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), key);
2173-
}
2174-
21752167
zend_compile_expr(&name_node, name_ast);
21762168
if (name_node.op_type == IS_CONST) {
21772169
convert_to_string(&name_node.u.constant);
@@ -2183,10 +2175,18 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
21832175
opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
21842176
}
21852177

2186-
opline->extended_value = ZEND_FETCH_LOCAL;
2187-
if (name_node.op_type == IS_CONST) {
2188-
if (zend_is_auto_global(Z_STR(name_node.u.constant))) {
2189-
opline->extended_value = ZEND_FETCH_GLOBAL;
2178+
if (name_node.op_type == IS_CONST &&
2179+
zend_is_auto_global(Z_STR(name_node.u.constant))) {
2180+
2181+
opline->extended_value = ZEND_FETCH_GLOBAL;
2182+
} else {
2183+
opline->extended_value = ZEND_FETCH_LOCAL;
2184+
/* there is a chance someone is accessing $this */
2185+
if (ast->kind != ZEND_AST_ZVAL
2186+
&& CG(active_op_array)->scope && CG(active_op_array)->this_var == (uint32_t)-1
2187+
) {
2188+
zend_string *key = zend_string_init("this", sizeof("this") - 1, 0);
2189+
CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), key);
21902190
}
21912191
}
21922192

0 commit comments

Comments
 (0)