user2707590
user2707590

Reputation: 1126

Get assigned variable inside a function

Is it possible to get the variable name to which a function is being assigned inside the function??

Example:

$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

Answers (2)

eatonphil
eatonphil

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

deceze
deceze

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

Related Questions