RE: [PHP] variable names

From: Date: Wed, 15 Nov 2000 03:02:08 +0000
Subject: RE: [PHP] variable names
Groups: php.general 
Request: Send a blank email to php-general+get-25337@lists.php.net to get a copy of this message
an work around is this: I suppose that the variable is somehow created from somewhere , right? otherwise you "would know it's name" Most probably is coming from a form and you can track it: Use HTTP_*_VARS .. my small peace of code to catch POSTed variables: if (($REQUEST_METHOD=='POST')) { /**************************************************************** Filter Posted Variables. ****************************************************************/ for(reset($HTTP_POST_VARS); $key=key($HTTP_POST_VARS); next($HTTP_POST_VARS)) { if($key != 'email') // check email for validity // check other staff you want $$key = $this; } # Now here $key ARE variable names. it works also in get. you can use this loop to assign the 'key's to an arrai which you can keep for your feature reference } Hope this helps... Cheers, Maxim Maletsky. -----Original Message----- From: Jan-Eric Duden [mailto:duden@uwyo.edu] Sent: Wednesday, November 15, 2000 8:26 AM To: Lars Torben Wilson Cc: php-general@lists.php.net Subject: Re: [PHP] variable names Hi! oops ... :) You're right ... my wanted feature is very difficult to implement ... - even saying which varname i really want is difficult i'll think about an work around ... Eric ----- Original Message ----- From: "Lars Torben Wilson" <torben@pinc.com> To: "Jan-Eric Duden" <jeduden@whisset.com> Cc: <php-general@lists.php.net> Sent: Tuesday, November 14, 2000 5:12 PM Subject: Re: [PHP] variable names > Jan-Eric Duden writes: > > Hi! > > > > Does anybody know if there is a function that returns the name of variable? > > I imagine something like this: > > > > $myvar="bla"; > > $name=GetVarName($myvar); > > > > $name=="myvar" > > > > Thks > > Eric > > No. A given variable can have several names; which one do you want? > For instance: > > <?php > $foo = 'Bob'; > $bar = &$foo; > $baz = &$foo; > > $name = getvarname($baz); > > echo $name; // what should the output be? > ?> > > In the above code, we end up with three names for the same slot in the > symbol table: $foo, $bar, and $baz are all different names for the > same value in memory. So should getvarname() return 'baz' in the above > case? If so, the you have to have known the name to write the function > call to start with. > > You may be able to emulate the effect you're after using variable > variables; that way, you can just use a string variable as the > variable name: > > <?php > $varname = 'foo'; > $$varname = 'Bob'; > echo "$varname == $foo\n"; > ?> > > ...which will output 'foo == Bob'. AFAIK that's about as close as you > can get, though. > > > > -- > +----------------------------------------------------------------+ > |Torben Wilson <torben@php.net> Netmill iTech| > |http://www.coastnet.com/~torben BåU]‡ûpîP,×8 > š)http://www.netmill.fi| > |Ph: 1 250 383-9735 torben@netmill.fi| > +----------------------------------------------------------------+ > > -- > 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 (#25337) next »