The complete list of superglobals variables:
1. $GLOBALS—An array of all global variables (Like the global keyword, this allows
you to access global variables inside a function—for example, as
$GLOBALS[‘myvariable’].)
2. $_SERVER—An array of server environment variables
3. $_GET—An array of variables passed to the script via the GET method
4. $_POST—An array of variables passed to the script via the POST method
5. $_COOKIE—An array of cookie variables
6. $_FILES—An array of variables related to file uploads
7. $_ENV—An array of environment variables
8 $_REQUEST—An array of all user input including the contents of input including
$_GET, $_POST, and $_COOKIE (but not including $_FILES)
9. $_SESSION—An array of session variables
Daily Archives: December 29, 2016
Understanding Variable Scope
The term scope refers to the places within a script where a particular variable is visible.
The six basic scope rules in PHP are as follows:
1. Built-in superglobal variables are visible everywhere within a script.
2. Constants, once declared, are always visible globally; that is, they can be used inside and outside functions.
3. Global variables declared in a script are visible throughout that script, but not inside
functions.
4. Variables inside functions that are declared as global refer to the global variables of
the same name.
5. Variables created inside functions and declared as static are invisible from outside
the function but keep their value between one execution of the function and the
next.
6. Variables created inside functions are local to the function and cease to exist when
the function terminates.
The arrays $_GET and $_POST and some other special variables have their own scope
rules.They are known as superglobals or autoglobals and can be seen everywhere, both
inside and outside functions.
Type Casting in PHP
You can pretend that a variable or value is of a different type by using a type cast.This
feature works identically to the way it works in C.You simply put the temporary type in
parentheses in front of the variable you want to cast.
For example,
$total= 0;
$totalamount=0.00;
$totalamount = (float)$total;
PHP’s Data Types
PHP supports the following basic data types:
1. Integer—Used for whole numbers
2. Float (also called double)—Used for real numbers
3. String—Used for strings of characters
4. Boolean—Used for true or false values
5. Array—Used to store multiple data items
6. Object—Used for storing instances of classes
Two special types are also available: NULL and resource.Variables that have not been
given a value, have been unset, or have been given the specific value NULL are of type
NULL. Certain built-in functions (such as database functions) return variables that have
the type resource. They represent external resources (such as database connections).