Skip to content

Commit 66af53c

Browse files
committed
Merge branch 'PHP-8.1'
2 parents 3be0ce6 + dab6226 commit 66af53c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Zend/tests/bug81684.phpt

Lines changed: 11 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8925,7 +8925,9 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */
89258925

89268926
/* Reproduce some of the zend_compile_assign() opcode fixup logic here. */
89278927
opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
8928-
switch (var_ast->kind) {
8928+
/* Treat $GLOBALS['x'] assignment like assignment to variable. */
8929+
zend_ast_kind kind = is_global_var_fetch(var_ast) ? ZEND_AST_VAR : var_ast->kind;
8930+
switch (kind) {
89298931
case ZEND_AST_VAR:
89308932
zend_emit_op_tmp(&assign_node, ZEND_ASSIGN, &var_node_w, &default_node);
89318933
break;

0 commit comments

Comments
 (0)