Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

original variable name passed to function? [duplicate]

Tags:

variables

php

Possible Duplicates:
PHP: Get name of variable passed as argument
How to get a variable name as a string in PHP?

If I have

$abc = '123';

function write($var){

}

How would I inside write find out that the variable now represented by $var was called $abc?

like image 213
Hailwood Avatar asked Dec 21 '10 20:12

Hailwood


People also ask

Can we use the same variable name in two different functions?

So, yes, you can have variables of the same name in different scopes.

What does it mean to pass a variable?

In simple terms... "Passing by value" means that you pass the actual value of the variable into the function. So, in your example, it would pass the value 9. "Passing by reference" means that you pass the variable itself into the function (not just the value).

How do you pass a variable name as an argument in Python?

Use a dict If you really really want, use your original code and do locals()[x][0] = 10 but that's not really recommended because you could cause unwanted issues if the argument is the name of some other variable you don't want changed. Show activity on this post. Show activity on this post.

How do you create a variable name from a string in Python?

String Into Variable Name in Python Using the vars() Function. Instead of using the locals() and the globals() function to convert a string to a variable name in python, we can also use the vars() function. The vars() function, when executed in the global scope, behaves just like the globals() function.


1 Answers

It's not possible. Even pass-by-reference won't help you. You'll have to pass the name as a second argument.

But what you have asked is most assuredly not a good solution to your problem.

like image 163
Jonah Avatar answered Dec 09 '22 21:12

Jonah