Re: Name of the variable

From: Date: Wed, 18 Oct 2000 19:04:44 +0000
Subject: Re: Name of the variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20965@lists.php.net to get a copy of this message
coolio writes: > Hi > > If I got $this_is_a_variable, how can I obtain the string > "this_is_a_variable"? > > -- > bye!, > coolio coolio@mdq.com You can't. Quick-explanation-as-I-understand-it: PHP stores variable values in something called a 'symbol table', and has another list of variable names. Each variable name points to an entry in the symbol table--so that when you use a variable name, PHP just looks for the value it's pointing to in the symbol table, and there's the value. AFAIK, the symbol table has no pointers back to the variable names. For one thing, any given entry in the symbol table can have more than one name--what PHP calls 'references'. So it'd have to know which one you wanted, or else return a list. For another reason, it might not make sense to try anyway. For instance, sometimes people want to do it so they can see, inside a function, what the original variable name of an argument was. But if they looked up the name of the passed argument, wouldn't they end up with the name of the parameter anyway? You can more or less fake this by using lists to store values--which, btw, makes bookkeeping much easier anyway--and then just check for the key value. Hope this is actually what you meant. I need way more coffee. :) -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#20965) next »