News:

Wondering if this will always be free?  See why free is better.

Main Menu

$GLOBALS - a n00b question

Started by Thunderace, March 06, 2006, 01:02:50 PM

Previous topic - Next topic

Thunderace

I'm still learning a lot so apologies in advance for this question I'm currently working on osCommerce alterring the code to remove $HTTP_?_VARS and so that it works natively globals off and as a function.

I believed, wrongly it seems that this meant removing instances of $GLOBALS and moving them to an SMF type array, in my case $osc_var[].

My question is ..

why do we use arrays like $context[] when everything exists already in $GLOBALS?

Parham

When you submit a form via a HTML page, PHP creates several variables.  Let's assume that a single form is submitted:
<input type="text" name="my_form" value="my_value" />
- if register_globals is enabled, then a $my_form variable will be created
- if you submitted the form with the method="POST" attribute, then a $_POST['my_form'] variable will be created
- in addition, a $GLOBALS['_POST']['my_form'] variable is created
- in addition, a $_POST['my_form'] variable is created
- if you submitted the form with the method="GET" attribute, then a $_GET['my_form'] variable will be created
- in addition, a $GLOBALS['_GET']['my_form'] variable is created
- in addition, a $_GET['my_form'] variable is created

ON TOP OF THESE, you have the $HTTP_GET_VARS and $HTTP_POST_VARS which aren't superglobals.  All this variety exists for backwards compatibility and security and just... well... variety!

One simple reason why $context[] would be used instead of $GLOBALS is that it's easier to type, or easier to understand what the variable is.  As far as style goes, using the $_* variables would probably be the best and easier since they're superglobals.  Of course you can use the $GLOBALS variable too, but that has its ambiguities.

Advertisement: