Page 1 of 1

Name of a Variable

Posted: Fri Feb 22, 2008 10:14 am
by anjanesh

Code: Select all

$abc = '55x';
echo foo($abc)
should output

Code: Select all

abc
I want to know the name of the variable.
Is this possible ?
Its possible to extract the classname using var_export but not a variable name.

Code: Select all

class clsA { public $var; }
$a = new clsA();
$a->var = 5;
$b = var_export($a, TRUE);
echo substr($b, 0, strpos($b, "::"));

Re: Name of a Variable

Posted: Fri Feb 22, 2008 11:36 am
by RobertGonzalez
There have been several code snippets published on our forums that can fetch a variable name (I posted one of them). If not, look in the user comments on the print_r() page of the manual. Several developers have posted tips on how to do what you are after.