3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait OptionzTrait { protected $_options = array(); public function setOptions(array $options) { $this->_options = array_replace_recursive( $this->_options, $options ); } public function getOptions() { return $this->_options; } } class Optionz { use OptionzTrait; protected $_options = array( 'fact' => null, 'inception' => array( 'options' => array() ) ); protected $_inception; public function __construct($options) { $this->setOptions($options); } public function stateFact() { echo $this->_options['fact']; } public function getInception() { if ($this->_inception === null) { $this->_inception = new static($this->_options['inception']['options']); } return $this->_inception; } } $optionz = new Optionz(array('inception' => array('fact' => 'it is known'))); $optionz->getInception()->stateFact(); // caveat: nested properties are only propagated initially $optionz->getInception()->setOptions(array('fact' => 'this works')); $optionz->setOptions(array('inception' => array('fact' => 'this doesnt')));
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, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Optionz and OptionzTrait define the same property ($_options) in the composition of Optionz. However, the definition differs and is considered incompatible. Class was composed in /in/EWgs7 on line 18
Process exited with code 255.
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 Fatal error: Optionz and OptionzTrait define the same property ($_options) in the composition of Optionz. However, the definition differs and is considered incompatible. Class was composed in /in/EWgs7 on line 18
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Optionz and OptionzTrait define the same property ($_options) in the composition of Optionz. However, the definition differs and is considered incompatible. Class was composed in /in/EWgs7 on line 43
Process exited with code 255.

preferences:
274.39 ms | 402 KiB | 327 Q