Jump to content

brackets vs $$ for variables


Shayna23

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.