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, $k) use ($code) { return $v['code'] == $code; }, ARRAY_FILTER_USE_BOTH); } } $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" } } array(1) { ["X"]=> array(2) { ["code"]=> int(101) ["reason"]=> string(10) "reason 101" } }

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:
55.08 ms | 402 KiB | 8 Q