php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28832 Operator = doesn't copy $GLOBALS array
Submitted: 2004-06-18 17:00 UTC Modified: 2005-02-15 01:38 UTC
Votes:3
Avg. Score:2.3 ± 1.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: tomas_matousek at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0RC3 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-06-18 17:00 UTC] tomas_matousek at hotmail dot com
Description:
------------
When the operator = is used on user created array on RHS this array will be copied to LHS. But if $GLOBALS variable is used on RHS a copy is not made. It seems like it behaves as =& when used on $GLOBALS which is IMHO not correct.


Reproduce code:
---------------
$x = 1;
$a = $GLOBALS;
$a["x"] = 2;
echo $x;             

Expected result:
----------------
1

Actual result:
--------------
2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-25 09:30 UTC] barond0 at gmail dot com
Is this possibly just the way globals work?  I am having the same problem with PHP 4.3.8 running on Fedora.

This is what I am trying:

$GLOBALS['test']="info";

$a=$GLOBALS['test']

I expect $a to be "info," but it does not work
 [2005-02-15 01:38 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

"Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables."

As of this, you're copying array of *references* to global variables. No wonder that you're still able to change them.
That's expected behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 21:01:32 2024 UTC