3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * Created by Code Cleanup Team * @author aldo.suwandi@aurea.com */ class GlobalConfig { private static $config; public static function setConfig($key, $value) { static::$config[$key] = $value; } public static function getConfig($key) { if (isset($GLOBALS[$key])) { return $GLOBALS[$key]; //temporary until refactoring finished //NOSONAR } else { if (!isset(static::$config[$key])) { return null; } else { return self::$config[$key]; } } } public static function unsetConfig($key) { unset(self::$config[$key]); } } $key = 'var1'; // for simple values $val = 456; GlobalConfig::setConfig($key, $val); $var1 = GlobalConfig::getConfig($key); var_dump($var1); // for objects $obj = new stdClass(); GlobalConfig::setConfig($key, $obj); $var2 = GlobalConfig::getConfig($key); var_dump($var2); // for array $arr = array('str 111222333','str 333444555'); GlobalConfig::setConfig($key, $arr); $var3 = GlobalConfig::getConfig($key); var_dump($var3);
based on bIp6v
Output for 5.3.0 - 7.3.0rc4
int(456) int(456) int(456)
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE in /in/CfbOH on line 13
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_VARIABLE in /in/CfbOH on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/CfbOH on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/CfbOH on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/CfbOH on line 9
Process exited with code 255.