|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-09 16:08 UTC] php at simplicate dot it
Description:
------------
When a variable variable is globalized into a function and then its value is set to a reference of another variable, the variable variable's value does not extend past that of the function.
Reproduce code:
---------------
$v = 'albert';
function test($var){
global $$var, $v;
$$var = &$v;
}
test('mmm');
var_dump($mmm);
exit;
// for further examples follow the link below:
// http://www.ourproperty.co.uk/test/index.php?code=0&allowin=SECurePHRase808
Expected result:
----------------
string(6) "albert"
Actual result:
--------------
NULL
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 06:00:01 2025 UTC |
What? sorry i really don't understand what you are talking about.. i am trying to set the value of $mmm... thats why it currently has no value... the behaviour of $$var should be $(value of $var) which is 'mmm' so the variable variable should resolve to $('mmm') not the value of $mmm as that would be rediculous, talk about recurssion!!! Anyway that is beside the point - i know i am correct because the whole thing works when not in the confines of a function. All this information can be found on the link that i posted. $v = 'albert'; $var = 'mmm'; $$var = &$v; This works fine...! so why putting it within a function does anything change... unless you can't safely globalize a variable variable... (ie. global $$var - but this works for other values) or variable variabling a reference changes the behaviour of the variable variable???? i couldn't find any information about this problem / feature in the references section or the variable variables section so where else can i look, i even searched the whole site for anything along the same lines??? And i reject the insinuation that i didn't check it in the first place... It also works if i remove the referencing to $v and just copy $v's value: $v = 'albert'; function test($var){ global $$var, $v; $$var = $v; // <--- no referencing!! } test('mmm'); var_dump($mmm); exit; The above code works fine and $mmm is set to the correct value "albert" outside of the functions reach. So what is going on, please can you give me a better explaination? this problem causes me no hinderance what-so-ever as i can code around it to my hearts content but anything that i see as a flaw in logic leaves me to worry about the reliability of a language. You may be a volenteer and you probably have to wade through a lot of requests, but if a jobs worth doing its worth doing well and i really think that you haven't fully looked into what i "took the time" to write. Thank you