3v4l.org

run code in 500+ 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;
Output for 8.5.0 - 8.5.7
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/FPKJP on line 36 Deprecated: Return type of LineItemList::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/FPKJP on line 15 SDSdSD
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22
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/FPKJP 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/FPKJP on line 15 SDSdSD
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
SDSdSD
Output for 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to LineItemBase::__construct() must be an instance of string, string given, called in /in/FPKJP on line 52 and defined in /in/FPKJP on line 46
Process exited with code 255.

preferences:
99.67 ms | 2026 KiB | 4 Q