Re: Register session in function without global?

From: Date: Thu, 22 Mar 2001 21:00:32 +0000
Subject: Re: Register session in function without global?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45181@lists.php.net to get a copy of this message
Well... Whadda ya know. Right after I sent the post I figured it out. (Solution? Variable variables!) function register_vars($reg_var) { // Make the $reg_var global $global_vars=explode("|", $reg_var); for ($i=0; $i<sizeof($global_vars); $i++) global $$global_vars[$i]; // Variable variables ... session setting code } register_vars("username|email|cellphone") ; This way I only make the nessesary variables global. // Tobias ""Tobias Talltorp"" <tobias@talltorp.com> wrote in message news:99dn35$duo$1@toye.p.sourceforge.net... > I am trying to register a session variable in a function without using the > global in the beginning. > The reason for this is that I don´t always know how many variables I am > going to register (I separate the different fields with | like this, > "username|email|cellphone" and explode them). > > Is there some way I can make all the variables in the function global, so I > can get the session variables registered? > > function test() { > global $username // <-- With this, it works. Without it, it doesn´t > session_start(); > $username="tobias"; > session_register("username"); > } > > The best I could come up with was (didn´t work): > global $HTTP_SESSION_VARS; > > Any thoughts? > // Tobias > > > > > > -- > 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 (#45181) next »