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);

preferences:
64.28 ms | 404 KiB | 5 Q