Shayna23 Posted January 9, 2014 Share Posted January 9, 2014 Hi everyone, I have a question. Which code is better at extracting variables: a.) foreach($_POST as $var=>$value){ ${$var} = $value; } -or- b.) foreach($_POST as $var=>$value){ $$var = $value; } Does version "b" have any pitfalls? Thank you. Quote Link to comment Share on other sites More sharing options...
trq Posted January 9, 2014 Share Posted January 9, 2014 It makes no difference. But as I said in your other thread, your example code suffers massive security vulnerabilities. Quote Link to comment Share on other sites More sharing options...
Shayna23 Posted January 9, 2014 Author Share Posted January 9, 2014 No, Mr. Administrator, in the "other thread," you answered.... no, you *snapped* and used foul language. If you are going to follow me around on every post I make, then delete my membership. I don't like being followed. Sir. Quote Link to comment Share on other sites More sharing options...
objnoob Posted January 9, 2014 Share Posted January 9, 2014 Shayna23, there are a number of ways to accomplish any and everything. Some are better practices than others, as well as being more secure and robust as others. Some are simply better for purposes of readability and understanding. I personally would choose ${$var}. Easy to see the separation! Quote Link to comment Share on other sites More sharing options...
Barand Posted January 9, 2014 Share Posted January 9, 2014 The smart thing to would be to follow up on the the advice you were given (http://www.php.net/manual/en/security.globals.php) rather than winge and post another topic with the same question Quote Link to comment Share on other sites More sharing options...
Shayna23 Posted January 9, 2014 Author Share Posted January 9, 2014 objnoob, thank you for your response. That is what I needed. To ALL the rest of you (who all ASSUMED that I don't have access to my own PHP.ini file, who ASSUMED that I wanted to have to all of a sudden have my Registered Globals ON, who ASSUMED that I don't know about the security risks, who ASSUMED that never try to emulate an environment to make things safer, and who ASSUMED that all you have to do is make "Auth=1" and now you have root), here's a little link for ya: http://uncyclopedia.wikia.com/wiki/Assume Now I know where all the people from the '90's Perl Newsgroup hang out. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted January 9, 2014 Share Posted January 9, 2014 I'm so, so sorry that the free professional (yes, professional... those of us with badges write PHP for a living) advice we have given you has somehow offended your delicate sensibilities. An edible bouquet will be shipped to you, with its fruit grown and sustained, in part, by our shameful tears. I think we can convince trq to end his own life, if you feel that your unique and entitled snowflake-ness needs something more than our communal genuflection. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.