3v4l.org

run code in 300+ PHP versions simultaneously
<?php //my variante final class StateOptions { public function __construct(array $options) { $this->options = $options; } private function validate() { if ($this->options === []) { return false; } return true; } public function getNextState() { return $this->options['nextState'] ?? 'defaultstate'; } } class BusinessLogicServiceOOp { public function changeState(StateOptions $stateOptions) { $this->changeTo($stateOptions->getNextState()); } public function changeTo(string $changeTo) { echo $changeTo; } } //array solution class BusinessLogicServiceLegacy { public function changeState(array $stateOptions) { /** Problem here is, that no validation ran on mandatory or optional flags or on valid flags from business perspective**/ $this->changeTo($stateOptions['nextState'] ?? 'defaultstate'); } public function changeTo(string $changeTo) { echo $changeTo; } } (new BusinessLogicServiceLegacy())->changeState([]); (new BusinessLogicServiceOOp())->changeState(new StateOptions([]));
Output for git.master, git.master_jit, rfc.property-hooks
defaultstate Deprecated: Creation of dynamic property StateOptions::$options is deprecated in /in/s7McT on line 8 defaultstate

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:
37.35 ms | 405 KiB | 5 Q