Skip to content

Commit 0570fca

Browse files
committed
Fix invalid opcode for ??= on $GLOBALS
Fixes #81684
1 parent 1b36555 commit 0570fca

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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
@@ -8919,7 +8919,9 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */
89198919

89208920
/* Reproduce some of the zend_compile_assign() opcode fixup logic here. */
89218921
opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
8922-
switch (var_ast->kind) {
8922+
/* Treat $GLOBALS['x'] assignment like assignment to variable. */
8923+
zend_ast_kind kind = is_global_var_fetch(var_ast) ? ZEND_AST_VAR : var_ast->kind;
8924+
switch (kind) {
89238925
case ZEND_AST_VAR:
89248926
zend_emit_op_tmp(&assign_node, ZEND_ASSIGN, &var_node_w, &default_node);
89258927
break;

0 commit comments

Comments
 (0)