Skip to content

Fix invalid opcode for ??= on $GLOBALS #7717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ PHP NEWS

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

- MBString:
. Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb)
Expand Down
11 changes: 11 additions & 0 deletions Zend/tests/bug81684.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Bug #81684: ??= on $GLOBALS produces an invalid opcode
--FILE--
<?php
$GLOBALS['x'] ??= 'x'; // Fatal error: Invalid opcode 23/1/0
var_dump($GLOBALS['x']);
echo "Done.\n";
?>
--EXPECT--
string(1) "x"
Done.
4 changes: 3 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8986,7 +8986,9 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */

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