Jump to content

using superglobals...


mkosmosports

Recommended Posts

Hello,

 

Im wondering about the usage of superglobals. Ive noticed a lot of tutorials tend to always put the superglobals variable into another variable. Ex. $testvar = $_POST['testvar'];

 

If youre not planning to manipulate its value, wouldnt it make more sense (and potentially faster because you dont need to define another variable) to always just refer to $_POST['testvar']?

 

Or are there some possible issues in doing this?

 

Im hoping someone could clear this up for me.

 

Thanks!

mkosmosports

 

Link to comment
Share on other sites

In my opinion; I think it's faster when it comes to "integrating" your super globals in your code; to declare a variable and put the super global in it. I just think it's easier to type "$variable" multiple times; then to type $_POST['testvar'] multiple times. But I guess you could always "copy/paste" either one and it would be just as fast.;D

Link to comment
Share on other sites

Also, don't you want to check the $_POSTed data to make sure it's valid and sanitized?  Would be easier to do that with a shorter version right?

 

Yes, you could always do

 

$_POST['data'] = trim (mysql_real_escape_string ($_POST['data']));

 

but wouldn't

 

$data = be easier?

Link to comment
Share on other sites

as far as language construct concerns there are no issues doing this, the only issues there are are the person who is coding it, his motives/decisions

 

although I have noticed this bug before in using naming $_POST variables

 

you can't say $_POST['text.moretext'] in PHP 4 I think, last time I checked

 

it changes that into 'text_moretext' , and replaces the dot

Link to comment
Share on other sites

Thanks for your input everyone.

 

I agree with your example revraz, but what about cases where your not manipulating the values, or the values are not user-inputted, like when using the $_SERVER or $_SESSION superglobals (I shouldnt of used the $_POST example in my intial post)?

 

In those cases, does it really just boil down to preference and coding styles? (rab, it looks like you agree with that)

 

I did read that as well regarding the $_POST superglobal dsaba. (it replaces all dots with underscores)

 

Thanks again.

 

 

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.