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 doesn't')));
Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.15
Parse error: syntax error, unexpected 't' (T_STRING), expecting ')' in /in/42D83 on line 50
Process exited with code 255.

preferences:
161.96 ms | 1387 KiB | 22 Q