--TEST-- PHP Spec test generated from ./variables/variable_kinds.php --FILE-- 1) return $i * factorial($i - 1); else if ($i == 1) return $i; else return 0; } $result = factorial(10); echo "\$result = $result\n"; echo "---------------- Global Constants -------------------\n"; const MAX_HEIGHT2 = 10.5; // define two c-constants const UPPER_LIMIT2 = MAX_HEIGHT2; define('COEFFICIENT_2', 2.345); // define two d-constants define('FAILURE2', TRUE); echo "MAX_HEIGHT2 = " . MAX_HEIGHT2 . "\n"; function globalConst() { echo "Inside " . __FUNCTION__ . "\n"; echo "MAX_HEIGHT2 = " . MAX_HEIGHT2 . "\n"; echo "COEFFICIENT_2 = " . COEFFICIENT_2 . "\n"; } globalConst(); echo "---------------- Global Variables using names directly -------------------\n"; $colors = array("red", "white", "blue"); $min = 10; $max = 100; $average = NULL; global $min, $max; // allowed, but serve no purpose function compute($p) { global $min, $max; global $average; $average = ($max + $min)/2; if ($p) { global $result; $result = 3.456; // initializes a global, creating it if necessary } } compute(TRUE); echo "\$average = $average\n"; echo "\$result = $result\n"; //var_dump($GLOBALS); echo "---------------- Global Variables using \$GLOBALS -------------------\n"; $GLOBALS['done'] = FALSE; var_dump($done); $GLOBALS['min'] = 10; $GLOBALS['max'] = 100; $GLOBALS['average'] = NULL; global $min, $max; // allowed, but serve no purpose function compute2($p) { $GLOBALS['average'] = ($GLOBALS['max'] + $GLOBALS['min'])/2; if ($p) { $GLOBALS['result'] = 3.456; // initializes a global, creating it if necessary } } compute2(TRUE); echo "\$average = $average\n"; echo "\$result = $result\n"; //var_dump($GLOBALS); echo "---------------- instance/static properties & constants -------------------\n"; class Point { const MAX_COUNT = 1000; private static $pointCount = 0; public $x; public $y; } --EXPECT-- ---------------- Local constants ------------------- Inside localConst COEFFICIENT_1 = 2.345 COEFFICIENT_1 = 2.345 FAILURE = 1 COEFFICIENT_1 = 2.345 FAILURE = 1 ---------------- Local variables ------------------- ---------------- Array elements ------------------- ---------------- Function statics ------------------- NULL $lv = 1, $fs = 1 $fs3 = 99 NULL $lv = 1, $fs = 2 $fs3 = 100 NULL $lv = 1, $fs = 3 $fs3 = 101 ---------------- recursive function example ------------------- $result = 3628800 ---------------- Global Constants ------------------- MAX_HEIGHT2 = 10.5 Inside globalConst MAX_HEIGHT2 = 10.5 COEFFICIENT_2 = 2.345 ---------------- Global Variables using names directly ------------------- $average = 55 $result = 3.456 ---------------- Global Variables using $GLOBALS ------------------- bool(false) $average = 55 $result = 3.456 ---------------- instance/static properties & constants -------------------