Which is better

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!

Moderator: General Moderators

Post Reply
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Which is better

Post by oldtimer »

Okay you have several methods I see.

Post, Get and request are the most often seen.

Is it better to use
$HTTP_POST_VARS['whatever'];
or
$_POST['whatever'];

I have been using the first but there is less typing for the 2nd :lol:

Or is even better to use
$_REQUEST['whatever']))
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

It's not a matter of which is best, it a matter of which is supported.

As of version 4.1 (I believe), the introduction of the new (2nd one) style evnironment variables supercedes the old style (1st one).

At present $HTTP_POST/GET_VARS['whatever'] are deprecated but still available (for backwards compatibility), this may not (most likely definitely not) be available in future releases.

Code being developed today should not use the old style vars as your software won't be future proof.

viewtopic.php?t=511

Regards,
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

So then $_POST or $_REQUEST should be used.

On another note. do I have to use caps in it? Or can i hae $_post ?
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Nope, they are predefined:

http://www.php.net/manual/en/language.v ... efined.php

You could do:

Code: Select all

$_post = array();
$_post = $_POST;
Regards,
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

But you'll probably find your code easier to maintain if you use the caps version especially since you'll then have the superglobal functionality as well.

Whether you use $_POST or $_REQUEST will depend - if you want to be sure that the data has been posted from a form use $_POST, if the data could come from either the URL, a posted form or a cookie use $_REQUEST. Being explicit as to where you are getting the information from can make it easier, once again, to maintain your code.

Mac
Post Reply