RE: [PHP] Is there a way to get a variable name as a string?
| From: | Daevid Vincent | Date: | Fri, 22 Jul 2005 19:51:53 +0000 |
| Subject: | RE: [PHP] Is there a way to get a variable name as a string? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-219237@lists.php.net to get a copy of this message | ||
> What I was thinking with debug_backtrace() is that you could get the
> information for the function that called the function you want the
> variable name for, *reducing* the likelyhood of duplicate values, but
> admitedly not eliminating it.
>
> You could also pass the name of the variable to the function:
>
> someFunction($foo, $varName=""){ print $varName; }
>
> call it with -> someFunction($bar, 'bar');
>
> That would definately get you what you want, but again it
> would be messy to look at.
Well if you called someFunction('bar');
Function someFunction($myVar)
{
global $$myVar;
echo "the variable name is '$myVar' and has the value of ".$$myVar;
}
But that relies on the global and is also a bit messy in a recursive
situation.