Reputation: 1126
Is it possible to get the variable name to which a function is being assigned inside the function??
$firstName = greet();
$John = greet();
function greet()
{
$name = /* things to get the "firstName" without the $ */;
echo "Hello $name!";
}
and this should print:
Hello firstName!
Hello John!
i want to do something like this, is it possible??
Upvotes: 1
Views: 47
Reputation: 13722
If you REALLY wanted to do something like this, you could write a data structure called Variable that stored the variable's name as well. But somehow I doubt you're going to have too much luck with OOP given the fact that you asked this question...
Upvotes: 0
Reputation: 522626
No. Not in any sane, feasible way.
There's also no sane reason to depend on this information in the first place.
Upvotes: 6