3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * This class is a hand written simplified version of PHP native `ArrayObject` * class, to show that it behaves differently than the PHP native implementation. */ class CustomArrayObject implements ArrayAccess, IteratorAggregate, Countable, Serializable { private $array; public function __construct(array $array = null) { $this->array = $array ?: array(); } public function offsetExists($offset) { return array_key_exists($offset, $this->array); } public function offsetGet($offset) { return $this->array[$offset]; } public function offsetSet($offset, $value) { if (null === $offset) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetUnset($offset) { unset($this->array[$offset]); } public function getIterator() { return new ArrayIterator($this->array); } public function count() { return count($this->array); } public function serialize() { return serialize($this->array); } public function unserialize($serialized) { $this->array = (array) unserialize((string) $serialized); } } $array = array('foo' => 'bar', 'nulled' => null); $native = new ArrayObject($array); $custom = new CustomArrayObject($array); $a = array_key_exists('missing', $custom); var_dump(isset($custom['missing']) || array_key_exists('missing', $custom));
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Return type of CustomArrayObject::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/pBVtn on line 26 Deprecated: Return type of CustomArrayObject::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/pBVtn on line 31 Deprecated: Return type of CustomArrayObject::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/pBVtn on line 36 Deprecated: Return type of CustomArrayObject::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/pBVtn on line 45 Deprecated: Return type of CustomArrayObject::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/pBVtn on line 50 Deprecated: Return type of CustomArrayObject::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/pBVtn on line 55 Deprecated: CustomArrayObject implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/pBVtn on line 17 Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, CustomArrayObject given in /in/pBVtn:75 Stack trace: #0 {main} thrown in /in/pBVtn on line 75
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, CustomArrayObject given in /in/pBVtn:75 Stack trace: #0 {main} thrown in /in/pBVtn on line 75
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/pBVtn on line 75 Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /in/pBVtn on line 76 bool(false)
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
bool(false)
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected ':' in /in/pBVtn on line 23
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/pBVtn on line 21
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/pBVtn on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/pBVtn on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/pBVtn on line 17
Process exited with code 255.

preferences:
284.74 ms | 401 KiB | 338 Q