PHP 5 and global variables

Since register_globals is turned off by default in PHP 5, I am curious if the following line would not work:
global $_POST
Will the code above work in PHP 5 with register_globals turned off?
msosnoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aherpsCommented:
Hi, from the site: http://devzone.zend.com/manual/reserved.variables.html 


HTTP POST variables: $_POST
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.
An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Loganathan NatarajanLAMP DeveloperCommented:
$_POST is a global variable ... you need not again to define as global variable... do you have any problem in accessing the variable?
0
Beverley PortlockCommented:
Just to be clear, there is a big difference between the "global" keyword and register_globals - they are NOTHING to do with each other.

Register_globals *creates* variables automatically from the URL query string. It is considered to be the biggest single security flaw in PHP which is why it is off by default. See http://uk2.php.net/register_globals

The "global" keyword makes variables defined outside a function visible inside a function. It is not considered good programming practice to use "global". See http://uk2.php.net/global

Finally there are special arrays that are defined as SUPER GLOBALS that are available in all contexts. These are things like $_POST, $_GET, $_SERVER, $_SESSION and $_COOKIE. See http://uk2.php.net/manual/en/language.variables.superglobals.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.