3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //var_dump(get_defined_constants(true)['Core']); class Foo { const ERR_SOME_CONST = 6001; const ERR_SOME_OTHER_CONST = 5001; function bar() { $x = 6001; $fooClass = new ReflectionClass ( 'Foo' ); $constants = $fooClass->getConstants(); $constants = get_defined_constants(true)['user']; var_dump($constants); $constName = null; foreach ( $constants as $name => $value ) { if ( $value == $x ) { $constName = $name; break; } } echo $constName; } } echo (new Foo)->bar();
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined index: user in /in/HCtCV on line 14 NULL Warning: Invalid argument supplied for foreach() in /in/HCtCV on line 19
Output for hhvm-3.10.0 - 3.12.0
NULL Warning: Invalid argument supplied for foreach() in /in/HCtCV on line 26
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/HCtCV on line 14
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/HCtCV on line 14
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/HCtCV on line 6
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_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/HCtCV on line 6
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/HCtCV on line 6
Process exited with code 255.