php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29702 $a=$GLOBALS works as $a=&$GLOBALS
Submitted: 2004-08-16 11:45 UTC Modified: 2004-08-16 16:34 UTC
From: andrea dot busia at axis-sv dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.1 OS: Win / Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrea dot busia at axis-sv dot it
New email:
PHP Version: OS:

 

 [2004-08-16 11:45 UTC] andrea dot busia at axis-sv dot it
Description:
------------
In this script seems that the $GLOBALS value is changed by the unset statement but I want to modify $ar, $GLOBALS must remain the same as before.


Reproduce code:
---------------
<?
$xml=array("aaa", "bbb", "ccc");
foo();

function foo() {
	var_dump($GLOBALS["xml"]);
	$ar=$GLOBALS;
	unset($ar['xml']);
	var_dump($GLOBALS["xml"]);
}
?>

Expected result:
----------------
array(3) {
  [0]=>
  string(3) "aaa"
  [1]=>
  string(3) "bbb"
  [2]=>
  string(3) "ccc"
}
array(3) {
  [0]=>
  string(3) "aaa"
  [1]=>
  string(3) "bbb"
  [2]=>
  string(3) "ccc"
}


Actual result:
--------------
array(3) {
  [0]=>
  string(3) "aaa"
  [1]=>
  string(3) "bbb"
  [2]=>
  string(3) "ccc"
}
NULL


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-16 12:02 UTC] derick@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

This is a feature.
 [2004-08-16 12:19 UTC] andrea dot busia at axis-sv dot it
Is it documented? I didn't find this in the manual, probably this is a documentation problem.
 [2004-08-16 12:28 UTC] andrea dot busia at axis-sv dot it
BTW:
Even if I try to use array_diff_assoc to have a "COPY" of $GLOBALS the script gives me the same result.
I thing this is a very big problem without a "array_copy" function.

I tried:
<?
$xml=array("aaa", "bbb", "ccc");
foo();

function foo() {
	var_dump($GLOBALS["xml"]);
	$ar=array_diff_assoc($GLOBALS, array());
	unset($ar['xml']);
	var_dump($GLOBALS["xml"]);
}
?>
 [2004-08-16 14:33 UTC] derick@php.net
http://no2.php.net/reserved.variables
read the section on $GLOBALS
 [2004-08-16 14:43 UTC] andrea dot busia at axis-sv dot it
I see the manual page but I don't see anywhere that I cannot COPY $GLOBALS content to an other variable.

Andrea Busia
 [2004-08-16 14:49 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.


 [2004-08-16 16:26 UTC] andrea dot busia at axis-sv dot it
I'm not asking support, I'm saying that this behaviour isn't written in the documentation and this is a problem!
 [2004-08-16 16:34 UTC] derick@php.net
It's explained just fine and there is NO bug here, please consult the mailinglists for help (otherwise called "support").
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 14:01:36 2025 UTC