3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Enter your code here, enjoy! $array = array("1" => "PHP code tester Sandbox Online", "foo" => "bar", 5 , 5 => 89009, "case" => "Random Stuff", "PHP Version" => phpversion() ); /** * Config class * * Simple class to store or get elements from configuration registry */ class Config implements \IteratorAggregate { /** @var array $data Data configuration array */ private $data = []; /** * Class constructor * @param array $data List of values to add to the configuration registry */ public function __construct(array $data = []) { $ritit = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($data)); $result = array(); foreach ($ritit as $leafValue) { $keys = array(); foreach (range(0, $ritit->getDepth()) as $depth) { $keys[] = $ritit->getSubIterator($depth)->key(); } $result[implode('.', $keys)] = $leafValue; } $this->data = $result; } /** * Retrieves elements from config array * * @param string $key * @return mixed returns a config value * @throws Exception when no $key found */ public function get($key) { if (!isset($this->data[$key])) { throw new \Exception('There is no entry for key: ' . $key); } return $this->data[$key]; } /** * Return true if value is empty for given key * * @param string $key * @return bool */ public function isEmpty($key) { return empty($this->data[$key]); } /** * IteratorAggregate interface required method * * @return \ArrayIterator */ public function getIterator() { return new \ArrayIterator($this->data); } } $config = new config($array); var_dump($config->dotnot());
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
Fatal error: Uncaught Error: Call to undefined method Config::dotnot() in /in/Bcd41:91 Stack trace: #0 {main} thrown in /in/Bcd41 on line 91
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Call to undefined method Config::dotnot() in /in/Bcd41 on line 91
Process exited with code 255.

preferences:
77.37 ms | 402 KiB | 62 Q