Skip to content

Commit 440676a

Browse files
committed
Fix invalid opcode for ??= on $GLOBALS
Fixes #81684
1 parent b9f9d4a commit 440676a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #81216 (Nullsafe operator leaks dynamic property name). (Dmitry)
7+
. Fixed bug #81684 (Using null coalesce assignment with $GLOBALS["x"] produces
8+
opcode error). (ilutov)
79

810
- MBString:
911
. Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb)

Zend/tests/bug81684.phpt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #81684: ??= on $GLOBALS produces an invalid opcode
3+
--FILE--
4+
<?php
5+
$GLOBALS['x'] ??= 'x'; // Fatal error: Invalid opcode 23/1/0
6+
var_dump($GLOBALS['x']);
7+
echo "Done.\n";
8+
?>
9+
--EXPECT--
10+
string(1) "x"
11+
Done.

Zend/zend_compile.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -8986,7 +8986,9 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */
89868986

89878987
/* Reproduce some of the zend_compile_assign() opcode fixup logic here. */
89888988
opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
8989-
switch (var_ast->kind) {
8989+
/* Treat $GLOBALS['x'] assignment like assignment to variable. */
8990+
zend_ast_kind kind = is_global_var_fetch(var_ast) ? ZEND_AST_VAR : var_ast->kind;
8991+
switch (kind) {
89908992
case ZEND_AST_VAR:
89918993
zend_emit_op_tmp(&assign_node, ZEND_ASSIGN, &var_node_w, &default_node);
89928994
break;

0 commit comments

Comments
 (0)