3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Collection implements \ArrayAccess, \Iterator { private $_array = array(); public function __invoke() { return $this->_array; } public function offsetExists($offset) { return array_key_exists($offset, $this->_array); } public function offsetGet($offset) { return $this->_array[$offset]; } public function offsetSet($offset, $value) { $this->_array[$offset] = $value; } public function offsetUnset($offset) { unset($this->_array[$offset]); } public function current() { return current($this->_array); } public function key() { return key($this->_array); } public function next() { return next($this->_array); } public function rewind() { return reset($this->_array); } public function valid() { return !is_null(key($this->_array)); } } $a = new Collection(); $a['alpha'] = 'blah'; $a['beta'] = 'yada'; $a['gamma'] = 'woot'; var_dump(current($a)); var_dump(next($a));
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Deprecated: Return type of Collection::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/KpE85 on line 8 Deprecated: Return type of Collection::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/KpE85 on line 9 Deprecated: Return type of Collection::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/KpE85 on line 10 Deprecated: Return type of Collection::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/KpE85 on line 11 Deprecated: Return type of Collection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/KpE85 on line 12 Deprecated: Return type of Collection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/KpE85 on line 14 Deprecated: Return type of Collection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/KpE85 on line 13 Deprecated: Return type of Collection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/KpE85 on line 16 Deprecated: Return type of Collection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/KpE85 on line 15 Deprecated: current(): Calling current() on an object is deprecated in /in/KpE85 on line 25 array(3) { ["alpha"]=> string(4) "blah" ["beta"]=> string(4) "yada" ["gamma"]=> string(4) "woot" } Deprecated: next(): Calling next() on an object is deprecated in /in/KpE85 on line 27 bool(false)
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(3) { ["alpha"]=> string(4) "blah" ["beta"]=> string(4) "yada" ["gamma"]=> string(4) "woot" } bool(false)

preferences:
131.43 ms | 410 KiB | 5 Q