3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CommandFactory { private $commandMappings; public function __construct(string $mappingFilename = 'default.json') { //$mappingsJSON = file_get_content($mappingFilename); $this->commandMappings = json_decode("{ 'command' : { 'SYSTEMS' : { 'OS1' : { 'Version' : 'command string', 'Version2' : 'command string', }, 'OS2' : { 'Version' : 'command string', 'Version' : 'command string' }, 'COMMANDOPTIONS' : ['var1', 'var2', 'var3'], }, 'add-Firewall' : { 'SYSTEMS' : { 'Ubuntu' : { '14' : 'command string', '11' : 'command string', }, 'Redhat' : { '13' : 'command string', '11' : 'command string' }, 'COMMANDOPTIONS' : ['port',], }, }", true); } public function getCommand(string $command, array $options): Command { $commandArray = $this->commandMappings[$command]; return new Command($commandArray, $options); } } class Command { private $options; private $mapping; public function __construct($mappings, $options) { $this->$options = $options; $this->mapping = $mappings; // check if options are are valid // potentially map in options here? } public function view(string $os, $version): string { // validate $os and $version $command = $this->mapping['SYSTEMS'][$os][$version]; //$command = str_replace(array_keys($options), $options, $command); return $command; } } // usage $factory = new CommandFactory(); $firewallCommand = $factory->getCommand('add-Firewall', ['port' => 23]); echo $firewallCommand->view('Ubuntu', '11');
Output for git.master, git.master_jit
Warning: Trying to access array offset on value of type null in /in/qlPGr on line 41 Warning: Array to string conversion in /in/qlPGr on line 54 Deprecated: Creation of dynamic property Command::$Array is deprecated in /in/qlPGr on line 54 Warning: Trying to access array offset on value of type null in /in/qlPGr on line 64 Warning: Trying to access array offset on value of type null in /in/qlPGr on line 64 Warning: Trying to access array offset on value of type null in /in/qlPGr on line 64 Fatal error: Uncaught TypeError: Command::view(): Return value must be of type string, null returned in /in/qlPGr:68 Stack trace: #0 /in/qlPGr(75): Command->view('Ubuntu', '11') #1 {main} thrown in /in/qlPGr on line 68
Process exited with code 255.
Output for rfc.property-hooks
Warning: Trying to access array offset on null in /in/qlPGr on line 41 Warning: Array to string conversion in /in/qlPGr on line 54 Deprecated: Creation of dynamic property Command::$Array is deprecated in /in/qlPGr on line 54 Warning: Trying to access array offset on null in /in/qlPGr on line 64 Warning: Trying to access array offset on null in /in/qlPGr on line 64 Warning: Trying to access array offset on null in /in/qlPGr on line 64 Fatal error: Uncaught TypeError: Command::view(): Return value must be of type string, null returned in /in/qlPGr:68 Stack trace: #0 /in/qlPGr(75): Command->view('Ubuntu', '11') #1 {main} thrown in /in/qlPGr on line 68
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:
47.92 ms | 401 KiB | 8 Q