Chapter 1 PHP Crash Course
Long style (
) is the most verbose.Note,however,
that it is deprecated and is therefore likely to be removed in the long term.This
style used to be the most portable but can now be disabled via the
configuration directive,which improves performance.
When you use the short style,the names of the variables in the script are the same as the
names of the form fields in the HTML form.You don’t need to declare the variables or
take any action to create these variables in your script.They are passed into your script,
essentially as arguments are passed to a function.If you are using this style,you can use a
variable such as
in the form creates the variable
in the processing script.
Such convenient access to variables is appealing,but before you simply turn on
,it is worth considering why the PHP development team set it
Having direct access to variables like this is very convenient,but it does allow you to make
programming mistakes that could compromise your scripts’security.With form variables
automatically turned into global variables like this,there is no obvious distinction between
variables that you have created and untrusted variables that have come directly from users.
If you are not careful to give all your own variables a starting value, your scripts’users
can pass variables and values as form variables that will be mixed with your own. If you
choose to use the convenient short style of accessing variables,you need to give all your
own variables a starting value.
Medium style involves retrieving form variables from one of the arrays
.One of the
arrays holds the details of all the
form variables.Which array is used depends on whether the method used to submit the
,respectively.In addition,all data submitted via
If the form was submitted via the
method,the data entered in the
will be stored in
.If the form was submitted via
,the data will
.In either case, the data will also be available in
These arrays are some of the superglobal arrays.We will revisit the superglobals when
we discuss variable scope.
If you are using an older version of PHP, you might not have access to
.Prior to version 4.1.0, this information was stored in arrays named
.We call this the long style.As mentioned previ-
ously,this style has been deprecated.There is no equivalent of
in this style.
If you are using long style, you can access a user’s response through