3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config = new class([ "item" => [ "I", "am", "a", "animal" => "beaver", ], "callable" => function(){ return true; } ]) implements ArrayAccess { public function __construct(array $initial = []) { foreach ($initial as $k => $v) { if (is_array($v)) { $this->$k = new self($v); } else $this->$k = $v; } } public function offsetGet($offset) { if (!isset($this->$offset)) { return ($this->$offset = new self()); } return $this->$offset; } public function offsetSet($offset, $value) { if (is_array($value)) { $this->$offset = new self($value); } else $this->$offset = $value; } public function offsetUnset($offset) { unset($this->$offset); } public function offsetExists($offset) { return isset($this->$offset); } public function array(self $object = null) : array { $array = []; if ($object === null) $object = $this; foreach ($object as $k => $v) { if ($v instanceof self) { $array[$k] = $this->array($v); } else $array[$k] = $v; } return $array; } public function __invoke(...$args) {} /* more magic here, perhaps ... */ }; $config["item"]["next"] = [ "I", "am", "a", "animal" => "badger", ]; # write undefined index of existing member $config[1][2] = "hello"; # write undefined index $config[5][8][10] = "whatever"; # write more undef index $config[9][10](); # read undef index and invoke it as function var_dump($config->array()); # show flattened array, not needed for iteration and whatever ... ?>
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of ArrayAccess@anonymous::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fa5Tk on line 37 Deprecated: Return type of ArrayAccess@anonymous::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fa5Tk on line 22 Deprecated: Return type of ArrayAccess@anonymous::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fa5Tk on line 30 Deprecated: Return type of ArrayAccess@anonymous::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/Fa5Tk on line 36 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$0 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$1 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$2 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$animal is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$item is deprecated in /in/Fa5Tk on line 17 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$callable is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$0 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$1 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$2 is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$animal is deprecated in /in/Fa5Tk on line 18 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$next is deprecated in /in/Fa5Tk on line 32 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$1 is deprecated in /in/Fa5Tk on line 24 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$2 is deprecated in /in/Fa5Tk on line 33 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$5 is deprecated in /in/Fa5Tk on line 24 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$8 is deprecated in /in/Fa5Tk on line 24 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$10 is deprecated in /in/Fa5Tk on line 33 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$9 is deprecated in /in/Fa5Tk on line 24 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$10 is deprecated in /in/Fa5Tk on line 24 array(5) { ["item"]=> array(5) { [0]=> string(1) "I" [1]=> string(2) "am" [2]=> string(1) "a" ["animal"]=> string(6) "beaver" ["next"]=> array(4) { [0]=> string(1) "I" [1]=> string(2) "am" [2]=> string(1) "a" ["animal"]=> string(6) "badger" } } ["callable"]=> object(Closure)#2 (0) { } [1]=> array(1) { [2]=> string(5) "hello" } [5]=> array(1) { [8]=> array(1) { [10]=> string(8) "whatever" } } [9]=> array(1) { [10]=> array(0) { } } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.61 ms | 409 KiB | 8 Q