3v4l.org

run code in 300+ PHP versions simultaneously
<?php // essentially tests/classes/array_access_012.phpt, with offsetGet returning by-ref class ArrayAccessImpl implements ArrayAccess { private $data = array(); public function offsetUnset($index) {} public function offsetSet($index, $value) { $this->data[$index] = $value; } public function &offsetGet($index) { return $this->data[$index]; } public function offsetExists($index) { return isset($this->data[$index]); } } $data = new ArrayAccessImpl(); $test = 'some data'; $data['element'] = NULL; // prevent notice $data['element'] = &$test; var_dump($data['element']);
Output for 8.1rc1
Deprecated: Return type of ArrayAccessImpl::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UmZcJ on line 17 Deprecated: Return type of & ArrayAccessImpl::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UmZcJ on line 13 Deprecated: Return type of ArrayAccessImpl::offsetSet($index, $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/UmZcJ on line 9 Deprecated: Return type of ArrayAccessImpl::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/UmZcJ on line 7 Fatal error: Uncaught Error: Cannot assign by reference to an array dimension of an object in /in/UmZcJ:25 Stack trace: #0 {main} thrown in /in/UmZcJ on line 25
Process exited with code 255.
Output for 7.4.0 - 7.4.23, 8.0.0 - 8.0.11
Fatal error: Uncaught Error: Cannot assign by reference to an array dimension of an object in /in/UmZcJ:25 Stack trace: #0 {main} thrown in /in/UmZcJ on line 25
Process exited with code 255.
Output for 7.3.0 - 7.3.30
Fatal error: Uncaught Error: Cannot assign by reference to overloaded object in /in/UmZcJ:25 Stack trace: #0 {main} thrown in /in/UmZcJ on line 25
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34
NULL
Output for 5.6.0 - 5.6.40
Fatal error: Cannot assign by reference to overloaded object in /in/UmZcJ on line 25
Process exited with code 255.

preferences:
48.01 ms | 465 KiB | 5 Q