Bug #71988 [NEW]: an element of $GLOBALS gets inexplicably rewritten
| From: | liv999 at hotmail dot com | Date: | Fri, 08 Apr 2016 12:22:41 +0000 |
| Subject: | Bug #71988 [NEW]: an element of $GLOBALS gets inexplicably rewritten | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200436@lists.php.net to get a copy of this message | ||
From: liv999 at hotmail dot com
Operating system: Linux/CentOS, Ubuntu
PHP version: Irrelevant
Package: *General Issues
Bug Type: Bug
Bug description:an element of $GLOBALS gets inexplicably rewritten
Description:
------------
I encountered a strange behavior of $GLOBALS array. After defining an
element of it, then using another element of it in some initializations
and calculations, the iniital element gets affected with values from the
operations performed, although it was not involved.
If I change the GLOBALS name to something else (like GLOBALS2) the
result is correct, thus it has to do with the GLOBALS properties.
Test script:
---------------
<?php
//initialization of an element of GLOBALS
$GLOBALS['categories'] =
array(1=>'z',2=>'x',3=>'c',4=>'v',5=>'r');
print_r($GLOBALS['categories']);
//another element
$GLOBALS['videos'] =
array(1=>'a',2=>'b',3=>'c',4=>'d');
//some operations
$videosCategories =
array(1=>array(2,3,4,5),2=>array(12,13,14,15),3=>array(22,23,24,25),4=>array(32,33,34,35));
foreach($videosCategories as $videoId =>$categories)
$GLOBALS['videos'][$videoId]['category'] =
implode(',',$categories);
//the initial element is reqritten
print_r($GLOBALS['categories']);
Expected result:
----------------
The 2 arrays should be the same, as it is the same GLOBALS element.
--
Edit bug report at https://bugs.php.net/bug.php?id=71988&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71988&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71988&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71988&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71988&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71988&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71988&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71988&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71988&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71988&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71988&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71988&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71988&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71988&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71988&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71988&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71988&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71988&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71988&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71988&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71988&r=mysqlcfg