3v4l.org

run code in 300+ PHP versions simultaneously
<?php class bar implements ArrayAccess { public $fields = []; /** * __construct * * @param mixed $eventInfo * @return void */ public function __construct($eventInfo) { // parent::__construct(); foreach ($eventInfo as $name => $value) { $this[$name] = $value; } } /** * getId * * @return void */ public function getId() { return $this; } /** * offsetExists * * @param mixed $name * @return void */ public function offsetExists($name) { return isset($this->fields[$name]); } /** * offsetGet * * @param mixed $name * @return void */ public function offsetGet($name) { return isset($this->fields[$name]) ? $this->fields[$name] : null; } /** * offsetSet * * @param mixed $name * @param mixed $value * @return void */ public function offsetSet($name, $value) { $this->fields[$name] = $value; } /** * offsetUnset * * @param mixed $name * @return void */ public function offsetUnset($name) { unset($this->fields[$name]); } } $eventInfo = ["name" => "A", "type" => "Programmer", "action" => "success"]; print_r((new bar($eventInfo))->getId());
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Deprecated: Return type of bar::offsetExists($name) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/X83NX on line 39 Deprecated: Return type of bar::offsetGet($name) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/X83NX on line 49 Deprecated: Return type of bar::offsetSet($name, $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/X83NX on line 61 Deprecated: Return type of bar::offsetUnset($name) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/X83NX on line 72 bar Object ( [fields] => Array ( [name] => A [type] => Programmer [action] => success ) )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
bar Object ( [fields] => Array ( [name] => A [type] => Programmer [action] => success ) )

preferences:
72.61 ms | 1638 KiB | 4 Q