|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78961 erroneous optimization of re-assigned $GLOBALS
Submitted: 2019-12-14 04:13 UTC Modified: 2019-12-16 09:04 UTC
From: szargv at qq dot com Assigned: dmitry (profile)
Status: Closed Package: opcache
PHP Version: 7.4.0 OS: CentOS 7 64Bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
2 + 50 = ?
Subscribe to this entry?

 [2019-12-14 04:13 UTC] szargv at qq dot com
PHP 7.4 + CentOS 7
in CLI mode
when opcache.enable_cli=1 it shows null
when opcache.enable_cli=0 it shows 3

my email is

Test script:
switch (1){
    case 1:
        $GLOBALS = array();
        $GLOBALS['td'] = array();
        $GLOBALS['td']['nsno'] = 3;

Expected result:
in CLI mode
when opcache.enable_cli=1 it shows null
when opcache.enable_cli=0 it shows 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-14 04:23 UTC] bugreports at gmail dot com

alias php-opcache='/usr/bin/php -d "" -d "opcache.enable_cli=1"'

php test.php

php-opcache test.php
Notice: Undefined index: nsno in test.php on line 7
 [2019-12-14 04:28 UTC] bugreports at gmail dot com
FWIW: Happens only with the '$GLOBALS = array();'
 [2019-12-14 04:32 UTC] bugreports at gmail dot com
there must be something corrupt because you can't even detect that in code - !isset($GLOBALS['bug_78961']['nsno']) don't fire the line before - was attempted to write some regression test for it

<?php declare(strict_types=1);
switch (1){
    case 1:
        $GLOBALS = [];
        $GLOBALS['bug_78961'] = [];
        $GLOBALS['bug_78961']['nsno'] = 3;
 [2019-12-14 15:59 UTC]
-Summary: switch+opcache +Summary: erroneous optimization of re-assigned $GLOBALS -Status: Open +Status: Verified
 [2019-12-14 15:59 UTC]
Due to commit 3ccd3ab[1], CSE optimizes this basically to

    $GLOBALS = array();
    $GLOBALS['td'] = array();
    $td['nsno'] = 3;

However, $the assignment to $GLOBALS severed the link to the
global variables, so that this optimization can not work.

The switch is irrelevant, by the way.

[1] <;a=commit;h=3ccd3aba90b4c0c95f1e0a457dbbc33c4524a4ed>
 [2019-12-16 09:04 UTC]
-Assigned To: +Assigned To: dmitry
 [2019-12-16 09:25 UTC]
Automatic comment on behalf of
Log: Fixed bug #78961 (erroneous optimization of re-assigned $GLOBALS)
 [2019-12-16 09:25 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 14:01:29 2024 UTC