Variables


Variables

A variable consists of variable name and mark in PHPoC.

Sign Name
The first letter The rest
$ Alphabet or _ (underscore) Alphabet, number or _ (underscore)

Examples are as follows:

Correct Example $_var = 0;
$var1 = 0;
$var_1 = 0;
Incorrect Example $123 = 0;       // name begins with number
$var_#% = 0; // name with special characters (#, %)

When defining a variable in PHPoC, the initial value should be given. More than one variable cannot be defined in a single line.

Correct Example $var1 = 0;
$var2 = 1; $var3 = 2;
Incorrect Example $var1;                      // no initial value
$var2 = 0, $var3 = 1; // two values are defined in a line

※ The maximum size of variable name is 31 bytes. The rest will be ignored.

Predefined Variables

$GLOBALS

This variable is a superglobal. Superglobals are always available in all scopes without the global keyword. The initial type of this varibale is integer but user can change it to an array as follows:

if(!is_array($GLOBALS))
    $GLOBALS = array(0, 0, 0, 0);
$GLOBALS[0] = 1;
$GLOBALS[1] = "abc";
$GLOBALS[2] = 3.14;
$GLOBALS[3] = array("a", "b", "c", "d");

Variable Scope

The scope of a variable is the context within which it is defined in PHPoC.

<?php
    $var1 = 0;       // $var1 is only available outside the function test
    function test()
    {
        $var2 = 1;     // $var2 is only available inside the function test
    }
?>
<?php
    $var1 = 0;
    function test()
    {
        global $var1;  // $var1 is available inside the function test
    }
?>

Variable Variables

PHPoC is not supporting variable variables.