3v4l.org

run code in 300+ PHP versions simultaneously
<?php $nest = new class([ "first" => [ "I", "am", "a", "animal" => "beaver" ] ]) 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 $thing = null) { $result = []; if (!$thing) $thing = $this; foreach ($thing as $k => $v) { if ($v instanceof self) { $result[$k] = $this->array($v); } else $result[$k] = $v; } return $result; } public function __invoke(...$args) {} }; $nest[1][2] = "hello"; # write undefined index $nest[5][8][10] = "whatever"; # write more undef index $nest[9][10](); # read undef index and invoke it var_dump($nest->array()); # show array(s), 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/iV3cF on line 34 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/iV3cF on line 19 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/iV3cF on line 27 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/iV3cF on line 33 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$0 is deprecated in /in/iV3cF on line 15 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$1 is deprecated in /in/iV3cF on line 15 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$2 is deprecated in /in/iV3cF on line 15 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$animal is deprecated in /in/iV3cF on line 15 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$first is deprecated in /in/iV3cF on line 14 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$1 is deprecated in /in/iV3cF on line 21 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$2 is deprecated in /in/iV3cF on line 30 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$5 is deprecated in /in/iV3cF on line 21 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$8 is deprecated in /in/iV3cF on line 21 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$10 is deprecated in /in/iV3cF on line 30 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$9 is deprecated in /in/iV3cF on line 21 Deprecated: Creation of dynamic property ArrayAccess@anonymous::$10 is deprecated in /in/iV3cF on line 21 array(4) { ["first"]=> array(4) { [0]=> string(1) "I" [1]=> string(2) "am" [2]=> string(1) "a" ["animal"]=> string(6) "beaver" } [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:
39.85 ms | 409 KiB | 8 Q