Last active
May 16, 2016 23:06
-
-
Save anytizer/f3c9abd7c3325a0b8614711f022e990f to your computer and use it in GitHub Desktop.
Global Variable Scopes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/plain'); | |
# Normal server environment | |
ini_set('display_errors', 'Off'); | |
error_reporting(0); | |
$test = 'TEST VALUE'; | |
function test() | |
{ | |
# Expect error here | |
echo "\$test: ", $test, "\r\n"; | |
# Ok | |
echo "\$GLOBALS['test']: ", $GLOBALS['test'], "\r\n"; | |
# Ok | |
global $test; | |
echo "\$test after `global \$test`: ", $test, "\r\n"; | |
} | |
test(); | |
/** | |
$test: | |
$GLOBALS['test']: TEST VALUE | |
$test after `global $test`: TEST VALUE | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment