3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Gridizer { /** * Get a squar-ish grid */ public function getGrid($array) { $grid_size = floor(sqrt(count($array))); $table = $this->chunk($table_cells, max($grid_size, 1)); foreach ($table as $row) { echo implode(' | ', $row) . PHP_EOL; } } /** * Create a Generator to chunk an incoming array into `$chunk_size` sized chunks */ public function chunk(array $array, $chunk_size) { $index = 0; while ($index < count($array)) { yield array_slice($array, $index, $chunk_size, true); $index += $chunk_size; } } } $foo = new Gridizer; echo $foo->getGrid(range(1, 100));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Gridizer::chunk(): Argument #1 ($array) must be of type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10.0) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
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 Warning: Undefined variable $table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Gridizer::chunk(): Argument #1 ($array) must be of type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10.0) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Gridizer::chunk(): Argument #1 ($array) must be of type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Argument 1 passed to Gridizer::chunk() must be of the type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught TypeError: Argument 1 passed to Gridizer::chunk() must be of the type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Argument 1 passed to Gridizer::chunk() must be of the type array, null given, called in /in/TGhWR on line 14 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(14): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Catchable fatal error: Argument 1 passed to Gridizer::chunk() must be of the type array, null given in /in/TGhWR on line 22
Process exited with code 255.
Output for 5.4.1 - 5.4.45
Parse error: syntax error, unexpected 'array_slice' (T_STRING) in /in/TGhWR on line 26
Process exited with code 255.

preferences:
163.75 ms | 401 KiB | 226 Q