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 git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.39 ms | 401 KiB | 8 Q