3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Collection { private $things; public function construct(Thing ...$things) { var_dump($things); $this->things = $things; } public function applyToAll() { /** * This was the function in question */ array_map(function($thing) { $thing->apply(); }, $this->things); } } interface Thing { public function apply(); } class FooThing implements Thing { public function apply() { echo 'applied the way Foo does things.'; } } class BarThing implements Thing { public function apply() { echo 'Bar had something different done to it.'; } } $collection = new Collection(new FooThing, new BarThing); $collection->applyToAll();
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given in /in/M6j9s:18 Stack trace: #0 /in/M6j9s(18): array_map(Object(Closure), NULL) #1 /in/M6j9s(46): Collection->applyToAll() #2 {main} thrown in /in/M6j9s on line 18
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 Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given in /in/M6j9s:18 Stack trace: #0 /in/M6j9s(18): array_map(Object(Closure), NULL) #1 /in/M6j9s(46): Collection->applyToAll() #2 {main} thrown in /in/M6j9s on line 18
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, null given in /in/M6j9s:20 Stack trace: #0 /in/M6j9s(20): array_map(Object(Closure), NULL) #1 /in/M6j9s(46): Collection->applyToAll() #2 {main} thrown in /in/M6j9s on line 20
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: array_map(): Expected parameter 2 to be an array, null given in /in/M6j9s on line 20
Output for 5.6.38, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
Warning: array_map(): Argument #2 should be an array in /in/M6j9s on line 20

preferences:
173.71 ms | 402 KiB | 178 Q