Created
May 15, 2016 10:27
-
-
Save bulton-fr/dec522d28bc1c554784deb41681e28d4 to your computer and use it in GitHub Desktop.
Test to create var in global scope from class method
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 | |
/** | |
* Test with https://3v4l.org/ZWMBt#v500 | |
* | |
* $test3 is created for 5.0.0 - 5.6.21, hhvm-3.9.1 - 3.12.0, 7.0.0 - 7.0.6 | |
*/ | |
$test1 = 'test1'; | |
var_dump($GLOBALS); | |
/** | |
array (size=9) | |
'_GET' => array (size=0) empty | |
'_POST' => array (size=0) empty | |
'_COOKIE' => array (size=0) empty | |
'_FILES' => array (size=0) empty | |
'_ENV' => array (size=0) empty | |
'_REQUEST' => array (size=0) empty | |
'_SERVER' => array (size=32) [...] | |
'GLOBALS' => &array | |
'test1' => string 'test1' (length=5) | |
*/ | |
class Foo | |
{ | |
public static function bar() | |
{ | |
//$test3 = 'test3'; | |
$GLOBALS['test3'] = 'test3'; | |
var_dump($GLOBALS); | |
} | |
} | |
$test2 = 'test2'; | |
Foo::bar(); | |
/** | |
array (size=9) | |
'_GET' => array (size=0) empty | |
'_POST' => array (size=0) empty | |
'_COOKIE' => array (size=0) empty | |
'_FILES' => array (size=0) empty | |
'_ENV' => array (size=0) empty | |
'_REQUEST' => array (size=0) empty | |
'_SERVER' => array (size=32) [...] | |
'GLOBALS' => &array | |
'test1' => string 'test1' (length=5) | |
'test2' => string 'test2' (length=5) | |
'test3' => string 'test3' (length=5) | |
*/ | |
var_dump(isset($test3)); //boolean true | |
var_dump($test3); //string 'test3' (length=5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment