Re: Re: Making variable global / accessing variable

From: Date: Mon, 01 Oct 2001 03:05:09 +0000
Subject: Re: Re: Making variable global / accessing variable
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-69411@lists.php.net to get a copy of this message
function MyFunction($td) {
        global $$td;
        echo $$td; // echos 3
        $$td = 5;
} $billybob = 3; MyFunction("billybob"); //Now $billybob = 5 -Jason Garber IonZoft.com At 10:25 PM 9/30/2001 -0400, you wrote:
I have used: global $$td; in the past with success... -Jason Garber IonZoft.com At 07:38 PM 9/30/2001 -0700, Justin Garrett wrote:
Maybe something similar to this? function test($td){
    $global = "global \$$td"."_error, \$$td"."_ok;";
    eval($global);
    $set = "\$$td"."_error = \"ERROR\"; \$$td"."_ok = \"OK\";";
    eval($set);
} test("foo"); echo "$foo_error $foo_ok"; -- Justin Garrett "Martin" <martin@radiok2r.de> wrote in message news:3BB755BB.408D290E@radiok2r.de...
Hello! How can I make a variable, which name I give to a function, global in this function? I want to make something like: function MyFunc($sVarName)
{    GLOBAL [$sVarName]_error, $sVarName_ok;
    ....
} So if $sVarName = "sHello", I want to access $sHello_error and $sHello_ok in this function. Any idea how I can make this variable gloabl and whats the easyst way to access this var then? Martin
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
At 10:25 PM 9/30/2001 -0400, Jason G. wrote:
I have used: global $$td; in the past with success... -Jason Garber IonZoft.com At 07:38 PM 9/30/2001 -0700, Justin Garrett wrote:
Maybe something similar to this? function test($td){
    $global = "global \$$td"."_error, \$$td"."_ok;";
    eval($global);
    $set = "\$$td"."_error = \"ERROR\"; \$$td"."_ok = \"OK\";";
    eval($set);
} test("foo"); echo "$foo_error $foo_ok"; -- Justin Garrett "Martin" <martin@radiok2r.de> wrote in message news:3BB755BB.408D290E@radiok2r.de...
Hello! How can I make a variable, which name I give to a function, global in this function? I want to make something like: function MyFunc($sVarName)
{    GLOBAL [$sVarName]_error, $sVarName_ok;
    ....
} So if $sVarName = "sHello", I want to access $sHello_error and $sHello_ok in this function. Any idea how I can make this variable gloabl and whats the easyst way to access this var then? Martin
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#69411) next »