3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DefaultMap implements ArrayAccess { private $array; private $default; public function __construct($default = null) { $this->array = []; $this->default = $default; } public function &offsetGet($key) { if (!isset($this->array[$key])) { $this->array[$key] = $this->default; } return $this->array[$key]; } public function offsetSet($key, $value) { $this->array[$key] = $value; } public function offsetExists($key) { return isset($this->array[$key]); } public function offsetUnset($key) { unset($this->array[$key]); } public function toArray() { return $this->array; } } $map = new DefaultMap(0); $map["foo"]++; var_dump($map->toArray());
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of DefaultMap::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/sU57S on line 24 Deprecated: Return type of & DefaultMap::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/sU57S on line 12 Deprecated: Return type of DefaultMap::offsetSet($key, $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/sU57S on line 20 Deprecated: Return type of DefaultMap::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/sU57S on line 28 array(1) { ["foo"]=> int(1) }

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:
27.8 ms | 403 KiB | 8 Q