Re: variable names

From: Date: Tue, 14 Nov 2000 23:26:12 +0000
Subject: Re: variable names
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-25273@lists.php.net to get a copy of this message
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 > 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 >

« previous php.general (#25273) next »