Bug #78961 [Ver->Csd]: erroneous optimization of re-assigned $GLOBALS

From: Date: Mon, 16 Dec 2019 09:25:51 +0000
Subject: Bug #78961 [Ver->Csd]: erroneous optimization of re-assigned $GLOBALS
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224328@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78961&edit=1 ID: 78961 Updated by: dmitry@php.net Reported by: szargv at qq dot com Summary: erroneous optimization of re-assigned $GLOBALS -Status: Verified +Status: Closed Type: Bug Package: opcache Operating System: CentOS 7 64Bit PHP Version: 7.4.0 Assigned To: dmitry Block user comment: N Private report: N New Comment: Automatic comment on behalf of dmitry@zend.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=6ef7e53c1be3670e77394cf9abcc7d9443b2769a Log: Fixed bug #78961 (erroneous optimization of re-assigned $GLOBALS) Previous Comments: ------------------------------------------------------------------------ [2019-12-14 15:59:27] cmb@php.net Due to commit 3ccd3ab[1], CSE optimizes this basically to $GLOBALS = array(); $GLOBALS['td'] = array(); $td['nsno'] = 3; var_dump($GLOBALS['td']['nsno']); 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] <http://git.php.net/?p=php-src.git;a=commit;h=3ccd3aba90b4c0c95f1e0a457dbbc33c4524a4ed> ------------------------------------------------------------------------ [2019-12-14 04:32:40] 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; if(!isset($GLOBALS['bug_78961']['nsno'])) { trigger_error('https://bugs.php.net/bug.php?id=78961'); } var_dump($GLOBALS['bug_78961']['nsno']); break; } ------------------------------------------------------------------------ [2019-12-14 04:28:18] bugreports at gmail dot com FWIW: Happens only with the '$GLOBALS = array();' ------------------------------------------------------------------------ [2019-12-14 04:23:03] bugreports at gmail dot com confirmed alias php-opcache='/usr/bin/php -d "zend_extension=opcache.so" -d "opcache.enable_cli=1"' php test.php int(3) php-opcache test.php Notice: Undefined index: nsno in test.php on line 7 NULL ------------------------------------------------------------------------ [2019-12-14 04:13:39] szargv at qq dot com Description: ------------ 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 szargv@qq.com Test script: --------------- <?php switch (1){ case 1: $GLOBALS = array(); $GLOBALS['td'] = array(); $GLOBALS['td']['nsno'] = 3; var_dump($GLOBALS['td']['nsno']); break; } Expected result: ---------------- in CLI mode when opcache.enable_cli=1 it shows null when opcache.enable_cli=0 it shows 3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78961&edit=1

« previous php.bugs (#224328) next »