3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { const X = [ 'code' => 101, 'reason' => 'reason 101', ]; const Y = [ 'code' => 102, 'reason' => 'reason 102', ]; public function getFooConstant($code) { $class = new \ReflectionClass(__CLASS__); $constants = $class->getConstants(); var_dump( $constants ); return array_filter($constants, function($v) use ($code) { return $v['code'] == $code; }, ARRAY_FILTER_USE_VALUE); } } $foo = new Foo(); var_dump( $foo->getFooConstant(101) );
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Fatal error: Uncaught Error: Undefined constant "ARRAY_FILTER_USE_VALUE" in /in/rvoiB:26 Stack trace: #0 /in/rvoiB(32): Foo->getFooConstant(101) #1 {main} thrown in /in/rvoiB on line 26
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Fatal error: Uncaught Error: Undefined constant "ARRAY_FILTER_USE_VALUE" in /in/rvoiB:26 Stack trace: #0 /in/rvoiB(32): Foo->getFooConstant(101) #1 {main} thrown in /in/rvoiB on line 26
Process exited with code 255.
Output for 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Warning: Use of undefined constant ARRAY_FILTER_USE_VALUE - assumed 'ARRAY_FILTER_USE_VALUE' (this will throw an Error in a future version of PHP) in /in/rvoiB on line 26 Warning: array_filter() expects parameter 3 to be int, string given in /in/rvoiB on line 26 NULL
Output for 7.2.0 - 7.2.33
array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Warning: Use of undefined constant ARRAY_FILTER_USE_VALUE - assumed 'ARRAY_FILTER_USE_VALUE' (this will throw an Error in a future version of PHP) in /in/rvoiB on line 26 Warning: array_filter() expects parameter 3 to be integer, string given in /in/rvoiB on line 26 NULL
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Notice: Use of undefined constant ARRAY_FILTER_USE_VALUE - assumed 'ARRAY_FILTER_USE_VALUE' in /in/rvoiB on line 26 Warning: array_filter() expects parameter 3 to be integer, string given in /in/rvoiB on line 26 NULL
Output for 5.6.0 - 5.6.26
array(2) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } ["Y"]=> array(2) { ["code"]=> int(102) ["reason"]=> string(10) "reason 102" } } Notice: Use of undefined constant ARRAY_FILTER_USE_VALUE - assumed 'ARRAY_FILTER_USE_VALUE' in /in/rvoiB on line 26 Warning: array_filter() expects parameter 3 to be long, string given in /in/rvoiB on line 26 NULL

preferences:
196.44 ms | 402 KiB | 188 Q