PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This function is to get all the variables that is passed by $_GET or $_POST. I've put this function in another php file, because this function will be accessed by several php files.
I don't use $_GET["foo"] or $_POST["bar"], because independently of the context that I'm using the site, I can have several variables with several names. I just created that function to use in all the possible contexts.
I don't want to offend anyone, but I just asked how can I do it, and I'm not questioning how should I design a site.
pedrosacosta wrote:and I'm not questioning how should I design a site.
That's right, you aren't. But I am. Meh, whatever.
PHP already has a function for this: extract. It even puts the variables into the right scope, which is the solution that your custom function can't deliver.
This function has the purpose to retrieve all variables that are passed in GET or POST in several contexts. This function is to be applied in several PHP files. Instead of copying this function to several PHP files, I just want that these PHP files will call this function.
That is the reason. I can't find any better way to design this. I just don't want to replicate this function.
For example, A.php, B.php, ..., Z.php files will need to retrieve the GET and POST variables. I just want a single place where this function will be to retrieve these variables to all the files.
And in A.php I've the line:
echo $var1;
This $var1 is a variable that is passed by GET or POST.
I don't put $var1=$_GET["var1"], because PHP offers a better way to create and retrieve variables in few lines.
Sorry, I don't want to offend anyone.
Last edited by pedrosacosta on Fri Apr 23, 2010 5:24 am, edited 1 time in total.
I'm newbie in PHP, but I think that your solution isn't what I want. I just want to access variables that are defined inside a function in another PHP file. Can you give me an example how can I do what I want using the extract method?