3v4l.org

run code in 300+ PHP versions simultaneously
<?php class States implements \ArrayAccess { private $states = []; /** * @param mixed $offset * * @return bool */ public function offsetExists($offset) { return array_key_exists($offset, $this->states); } /** * @param mixed $offset * * @throws UnknownStateException * * @return AllianceState */ public function offsetGet($offset) { if ( ! $this->offsetExists($offset)) { throw new UnknownStateException(); } return $this->states[$offset]; } /** * @param mixed $offset * @param mixed $value * * @throws InvalidArgumentException */ public function offsetSet($offset, $value) { $offset = count($this->states); $this->states[$offset] = $value; } /** * @param mixed $offset * * @throws UnknownStateException */ public function offsetUnset($offset) { unset($this->states[$offset]); $this->states = array_values($this->states); } } $states = new States(); $states->add('foo'); $states->add('bar'); var_dump($states);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of States::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/b89Xl on line 13 Deprecated: Return type of States::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/b89Xl on line 25 Deprecated: Return type of States::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/b89Xl on line 40 Deprecated: Return type of States::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/b89Xl on line 53 Fatal error: Uncaught Error: Call to undefined method States::add() in /in/b89Xl:62 Stack trace: #0 {main} thrown in /in/b89Xl on line 62
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:
35.85 ms | 402 KiB | 8 Q