|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-04-08 12:37 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2016-04-08 12:37 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 20 20:00:01 2025 UTC |
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.