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); var_dump($this->commandMappings); } 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) { var_dump($mappings); //$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 "je;;"; } } // usage $factory = new CommandFactory(); $firewallCommand = $factory->getCommand('add-Firewall', ['port' => 23]); echo $firewallCommand->view('Ubuntu', '11');
Output for 8.3.0 - 8.3.4, 8.3.6
NULL Warning: Trying to access array offset on null in /in/gipbL on line 42 NULL je;;
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 NULL Warning: Trying to access array offset on null in /in/gipbL on line 42 NULL je;;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
NULL Warning: Trying to access array offset on value of type null in /in/gipbL on line 42 NULL je;;
Output for 7.4.0 - 7.4.33
NULL Notice: Trying to access array offset on value of type null in /in/gipbL on line 42 NULL je;;
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
NULL NULL je;;
Output for 5.6.0 - 5.6.40
Fatal error: Default value for parameters with a class type hint can only be NULL in /in/gipbL on line 8
Process exited with code 255.

preferences:
193.25 ms | 401 KiB | 291 Q