3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait GenericList { public function __call($func, $argv) { echo "__call called \n"; if (!is_callable($func) || substr($func, 0, 6) !== 'array_') { throw new \BadMethodCallException(__CLASS__.'->'.$func); } return call_user_func_array($func, array_merge(array($this->getArrayCopy()), $argv)); } final public function offsetUnset($offset) { parent::offsetUnset($offset); } final public function sort($preserveKeys = false) { if($preserveKeys) parent::ksort(); else parent::exchangeArray (\Arr::reindex(parent::getArrayCopy ())); } final public function clear(){ parent::exchangeArray([]); } } final class LineItemList extends \ArrayObject { use GenericList; public function offsetSet($offset, $value) { if (!($value instanceof LineItemBase)) { throw new \InvalidArgumentException("Value has to be a instance of LineItemBase"); } parent::offsetSet($offset, $value); } } class LineItemBase{ public $blah; public function __construct(string $blah){ $this->blah = $blah; } } $list = new LineItemList(); $list []= new LineItemBase('SDSdSD'); echo $list [0]->blah; $list->array_search('adf');
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of LineItemList::offsetSet($offset, $value) should either be compatible with ArrayObject::offsetSet(mixed $key, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/foEJX on line 36 Deprecated: Return type of GenericList::offsetUnset($offset) should either be compatible with ArrayObject::offsetUnset(mixed $key): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/foEJX on line 15 SDSdSD__call called Fatal error: Uncaught TypeError: array_search(): Argument #2 ($haystack) must be of type array, string given in /in/foEJX:12 Stack trace: #0 /in/foEJX(12): array_search(Array, 'adf') #1 /in/foEJX(54): LineItemList->__call('array_search', Array) #2 {main} thrown in /in/foEJX on line 12
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:
60.43 ms | 402 KiB | 8 Q