3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LargeObject { protected $array; public function __construct() { $this->array = array_fill(0, 2000, 17); } public function getItemProcessor(): Closure { // Try with and without 'static' here return function () { // do some processing unrelated to $this }; } } $start = microtime(true); $processors = []; for ($i = 0; $i < 2000; $i++) { $lo = new LargeObject(); $processors[] = $lo->getItemProcessor(); } $memory = memory_get_usage() >> 20; $time = (microtime(true) - $start) * 1000; printf("This took %dms and %dMB of memory\n", $time, $memory);
Output for 8.5.0
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36864 bytes) in /in/QnDuA on line 7 Stack trace: #0 /in/QnDuA(7): array_fill(0, 2000, 17) #1 /in/QnDuA(22): LargeObject->__construct() #2 {main}
Process exited with code 255.
Output for 8.2.18 - 8.2.29, 8.3.5 - 8.3.27, 8.4.1 - 8.4.14
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 36864 bytes) in /in/QnDuA on line 7
Process exited with code 255.
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Out of memory (allocated 31457280 bytes) (tried to allocate 36864 bytes) in /in/QnDuA on line 7 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.1, 8.1.28 - 8.1.33
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 69632 bytes) in /in/QnDuA on line 7
Process exited with code 255.
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 31457280) (tried to allocate 69632 bytes) in /in/QnDuA on line 7 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.

preferences:
124.59 ms | 483 KiB | 5 Q