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 = array()) { $this->array = $array; } public function offsetExists($offset) { echo 'called '; 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() { echo 'iterator created '; 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); error_reporting(-1); $a = array_key_exists('missing', $custom); var_dump($a); var_dump(isset($custom['missing']) || array_key_exists('missing', $custom));
Output for git.master, git.master_jit, rfc.property-hooks
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/J9XHb 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/J9XHb on line 32 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/J9XHb on line 37 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/J9XHb on line 46 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/J9XHb on line 51 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/J9XHb on line 57 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/J9XHb on line 17 Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, CustomArrayObject given in /in/J9XHb:78 Stack trace: #0 {main} thrown in /in/J9XHb on line 78
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.45 ms | 403 KiB | 8 Q