|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 18:00:01 2025 UTC |
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"]); } ?>