3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SwitchStage{ function __construct( public array $branches = [], public ?int $default = null ) {} function branch(int $case, int $then) { $this->branches[] = (object) ['case' => $case, 'then' => $then]; return $this; } function default(int $default) { $this->default = $default; return $this; } } $x = (new SwitchStage()) ->branch(case: 1, then: 2) ->branch(case: 3, then: 4) ->default(5); var_dump($x); $x = new SwitchStage([ ['case' => 1, 'then' => 2], ['case' => 3, 'then' => 4], ], default: 5); var_dump($x);
Output for git.master, git.master_jit, rfc.property-hooks
object(SwitchStage)#1 (2) { ["branches"]=> array(2) { [0]=> object(stdClass)#2 (2) { ["case"]=> int(1) ["then"]=> int(2) } [1]=> object(stdClass)#3 (2) { ["case"]=> int(3) ["then"]=> int(4) } } ["default"]=> int(5) } object(SwitchStage)#4 (2) { ["branches"]=> array(2) { [0]=> array(2) { ["case"]=> int(1) ["then"]=> int(2) } [1]=> array(2) { ["case"]=> int(3) ["then"]=> int(4) } } ["default"]=> int(5) }

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:
30.49 ms | 407 KiB | 5 Q