I am using PHP
- to implement an HTML form and
- for validation of the data submitted by the form.
There are two scripts. In order for the second script to know about values assigned by the first, I am using a POST method with the following code:
foreach (${"_".$_SERVER["REQUEST_METHOD"]} as $k => $v) $$k = $v;
to retrieve each of the (key => value) elements of the POST (or GET) associative array and create variables with those names and values.
I don't remember where I found this code, but I was impressed with it, once I worked out how it does its job.
It works well, but I know if I go back to it in a few months, I won't remember how it works unless I add extensive comments, and I'd prefer to use something I can immediately understand and which fits well with my non-idiomatic style.
Does anyone have any suggestions?
CONCLUSION:
I like the idea of extract() and I'll probably use it. Thankyou all.
I should explain perhaps why some of the points raised in the answers below don't bother me:
- The form is only visible on a Company intranet. The users have trouble figuring out which button to click on, much less 'how to attack it?'
- The users enter simple values in the form fields: x and y co-ordinates, measurements, lot numbers. Validation is straightforward. If it doesn't work, I'm on site, they'll come and ask me why.
- The values end up in a DB which only my apps access. I don't allow anything which might constitute SQL injection.
- I don't have to worry about other developers. I'm the only developer and I'm just trying to overcome the corporate culture of using bloated Windows applications for everything when simple web apps will do. I had a heated discussion with a senior engineer the other day about why I use a MySQL database, when you can do anything with Access & Excel.
But I shouldn't get myself started ...