Bug #78475 [NEW]: Unsetting or assigning a value to $GLOBALS makes it stop working

From: Date: Thu, 29 Aug 2019 18:14:51 +0000
Subject: Bug #78475 [NEW]: Unsetting or assigning a value to $GLOBALS makes it stop working
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222486@lists.php.net to get a copy of this message
From:             ayg at aryeh dot name
Operating system: 
PHP version:      7.3.9
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Unsetting or assigning a value to $GLOBALS makes it stop working

Description:
------------
$GLOBALS contains a reference to a magical array that has all the
globals in it. Unsetting or assigning a value to it seems to forevermore
lose the reference to this magical array, making $GLOBALS a regular old
variable that has no connection to defined globals (although it's still
a superglobal).

Unsetting or assigning to $GLOBALS probably should fail, just like $this
does. I spent some time today trying to debug a scenario where
$GLOBALS['someVar'] did not equal $someVar after I had written "global
$someVar". It turned out to be because someone had unset $GLOBALS
somewhere (they were trying to clear all global variables and restore
them to an earlier state). This is really confusing and should be
disallowed. Or at least produce a notice or something.

Test script:
---------------
$a = 1;
unset( $GLOBALS );
function f() {
  global $a;
  unset( $GLOBALS ); // $GLOBALS = []; is the same
  var_dump( $a );
  var_dump( isset( $GLOBALS['a' ) );
}
f();

Expected result:
----------------
Either:

int(1)
bool(true)

Or:

NULL
bool(false)

Actual result:
--------------
int(1)
bool(false)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=78475&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=78475&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=78475&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=78475&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=78475&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=78475&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=78475&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=78475&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=78475&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=78475&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=78475&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78475&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=78475&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=78475&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=78475&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=78475&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=78475&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=78475&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#222486) next »