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 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.
Output for 8.0.0 - 8.0.30
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.
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
SDSdSD__call called Warning: array_search() expects parameter 2 to be array, string given in /in/foEJX on line 12
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/foEJX on line 52 and defined in /in/foEJX on line 46
Process exited with code 255.

preferences:
232.5 ms | 401 KiB | 287 Q