3v4l.org

run code in 300+ PHP versions simultaneously
<?php # http://scribu.net/blog/defaultdict-in-php.html class Defaultdict implements ArrayAccess { private $container = array(); private $default; public function __construct( $default ) { $this->default = $default; } public function offsetSet( $offset, $value ) { if ( is_null($offset) ) { trigger_error( sprintf( "Trying to use %s as a list.", __CLASS__ ), E_USER_WARNING ); return; } $this->container[$offset] = $value; } public function offsetExists( $offset ) { return true; } public function offsetUnset( $offset ) { unset( $this->container[$offset] ); } public function &offsetGet( $offset ) { if ( !isset( $this->container[$offset] ) ) { if ( is_callable($this->default) ) $value = call_user_func( $this->default, $offset ); else $value = $this->default; $this->container[$offset] = $value; } return $this->container[$offset]; } } $counts = new Defaultdict(1); $counts['English']++; print_r(array_keys($counts));
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Defaultdict::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/nkm4c on line 16 Deprecated: Return type of & Defaultdict::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/nkm4c on line 22 Deprecated: Return type of Defaultdict::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/nkm4c on line 9 Deprecated: Return type of Defaultdict::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/nkm4c on line 19 Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, Defaultdict given in /in/nkm4c:35 Stack trace: #0 /in/nkm4c(35): array_keys(Object(Defaultdict)) #1 {main} thrown in /in/nkm4c on line 35
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:
26.68 ms | 407 KiB | 5 Q