<?php
class MyThing implements \ArrayAccess {
protected $storage = [];
public function __construct($values = array()) {
foreach ($values as $name => $value) {
$this->offsetSet($name, $value);
}
}
public function offsetGet($name) {
if (isset($this->storage[$name])) {
return $this->storage[$name];
}
}
public function offsetSet($name, $value) {
$this->storage[$name] = $value;
}
public function offsetUnset($name) {
unset($this->storage[$name]);
}
public function offsetExists($name) {
return isset($this->storage[$name]);
}
}
function printArray(array $a) {
print_r($a);
}
$thing = new MyThing(['foo' => 'bar']);
printArray($thing);
Deprecated: Return type of MyThing::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/B3ngF on line 26
Deprecated: Return type of MyThing::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/B3ngF on line 12
Deprecated: Return type of MyThing::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/B3ngF on line 18
Deprecated: Return type of MyThing::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/B3ngF on line 22
Fatal error: Uncaught TypeError: printArray(): Argument #1 ($a) must be of type array, MyThing given, called in /in/B3ngF on line 37 and defined in /in/B3ngF:32
Stack trace:
#0 /in/B3ngF(37): printArray(Object(MyThing))
#1 {main}
thrown in /in/B3ngF on line 32
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: printArray(): Argument #1 ($a) must be of type array, MyThing given, called in /in/B3ngF on line 37 and defined in /in/B3ngF:32
Stack trace:
#0 /in/B3ngF(37): printArray(Object(MyThing))
#1 {main}
thrown in /in/B3ngF on line 32
Process exited with code 255.
Fatal error: Uncaught TypeError: Argument 1 passed to printArray() must be of the type array, object given, called in /in/B3ngF on line 37 and defined in /in/B3ngF:32
Stack trace:
#0 /in/B3ngF(37): printArray(Object(MyThing))
#1 {main}
thrown in /in/B3ngF on line 32
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Catchable fatal error: Argument 1 passed to printArray() must be of the type array, object given, called in /in/B3ngF on line 37 and defined in /in/B3ngF on line 32
Process exited with code 255.