3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayClass implements ArrayAccess { private $container = []; public function __construct(array $array) { $this->container = $array; } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return $this->offsetExists($offset) ? $this->container[$offset] : false; } } $_POST['aa'] = "dd"; $_POST['bb'] = "xd"; $post = new ArrayClass($_POST); print_r( [ $post['aa'], $post['bb'], $post['cc'], $post ] );
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Return type of ArrayClass::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/DsX47 on line 17 Deprecated: Return type of ArrayClass::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/DsX47 on line 25 Deprecated: Return type of ArrayClass::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/DsX47 on line 9 Deprecated: Return type of ArrayClass::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/DsX47 on line 21 Array ( [0] => dd [1] => xd [2] => [3] => ArrayClass Object ( [container:ArrayClass:private] => Array ( [aa] => dd [bb] => xd ) ) )
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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 ( [0] => dd [1] => xd [2] => [3] => ArrayClass Object ( [container:ArrayClass:private] => Array ( [aa] => dd [bb] => xd ) ) )

preferences:
209.31 ms | 407 KiB | 331 Q