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.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.33, 8.0.0 - 8.0.30
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.33
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:
194.65 ms | 401 KiB | 300 Q