@ 2015-11-23T14:19:10Z <?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 $_inception;
public function __construct($options)
{
$this->_options = array(
'fact' => null,
'inception' => array(
'options' => array()
)
);
$this->setOptions($options);
}
public function stateFact()
{
echo $this->_options['fact'] . "\n";
}
public function getInception()
{
if ($this->_inception === null) {
$this->_inception = new static($this->_options['inception']['options']);
}
return $this->_inception;
}
}
$optionz = new Optionz(array('inception' => array('options' => array('fact' => 'it is known'))));
$optionz->getInception()->stateFact();
// caveat: nested properties are only propagated initially
$optionz->getInception()->setOptions(array('fact' => 'this works'));
$optionz->getInception()->stateFact();
$optionz->setOptions(array('inception' => array('options' => array('fact' => 'this doesnt'))));
$optionz->getInception()->stateFact();
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 , 7.0.0 - 7.0.20 , 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 it is known
this works
this works
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
it is known
this works
this works
preferences:dark mode live preview
165.67 ms | 402 KiB | 225 Q