3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IteratorWithFilter { public $generator; public function __construct(array $data) { $this->generator = new \ArrayIterator($data); } public function filter() { $this->generator = new \CallbackFilterIterator($this->generator, function ($row) { return true; }); return $this; } } function createIterator() { $iter = new IteratorWithFilter([['a'], ['b']]); return $iter->filter(); } for ($i = 0; $i < 50 * 1000; $i++) { createIterator(); if (($i % 1000) === 0) { // gc_collect_cycles(); // explicit GC does not help... echo round(memory_get_usage() / (1024 * 1024), 3) . " MiB\n"; } }
Output for 7.4.2 - 7.4.10
0.374 MiB 1.65 MiB 2.933 MiB 4.154 MiB 5.678 MiB 6.898 MiB 8.119 MiB 9.59 MiB 10.81 MiB 12.031 MiB 13.608 MiB 14.828 MiB 16.049 MiB 17.27 MiB 18.991 MiB 20.211 MiB 21.432 MiB 22.653 MiB 23.873 MiB 25.094 MiB 26.849 MiB 28.07 MiB 29.29 MiB 30.511 MiB 31.732 MiB 32.952 MiB 34.173 MiB 36.394 MiB 37.614 MiB 38.835 MiB 40.056 MiB 41.277 MiB 42.497 MiB 43.718 MiB 45.651 MiB 46.871 MiB 48.092 MiB 49.313 MiB 50.534 MiB 51.754 MiB 52.975 MiB 54.196 MiB 55.416 MiB 56.637 MiB 57.858 MiB 59.078 MiB 60.299 MiB 61.52 MiB 62.741 MiB Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4096 bytes) in /in/UpmHK on line 23
Process exited with code 255.
Output for 7.4.0 - 7.4.1
0.374 MiB 1.65 MiB 2.933 MiB 4.154 MiB 5.677 MiB 6.898 MiB 8.119 MiB 9.589 MiB 10.81 MiB 12.031 MiB 13.608 MiB 14.828 MiB 16.049 MiB 17.27 MiB 18.99 MiB 20.211 MiB 21.432 MiB 22.653 MiB 23.873 MiB 25.094 MiB 26.849 MiB 28.069 MiB 29.29 MiB 30.511 MiB 31.731 MiB 32.952 MiB 34.173 MiB 36.394 MiB 37.614 MiB 38.835 MiB 40.056 MiB 41.276 MiB 42.497 MiB 43.718 MiB 45.651 MiB 46.871 MiB 48.092 MiB 49.313 MiB 50.533 MiB 51.754 MiB 52.975 MiB 54.195 MiB 55.416 MiB 56.637 MiB 57.858 MiB 59.078 MiB 60.299 MiB 61.52 MiB 62.74 MiB Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4096 bytes) in /in/UpmHK on line 23
Process exited with code 255.
Output for 7.3.0 - 7.3.22
0.374 MiB 1.65 MiB 2.933 MiB 4.154 MiB 5.677 MiB 6.898 MiB 8.119 MiB 9.59 MiB 10.81 MiB 12.031 MiB 13.608 MiB 14.828 MiB 16.049 MiB 17.27 MiB 18.991 MiB 20.211 MiB 21.432 MiB 22.653 MiB 23.873 MiB 25.094 MiB 26.849 MiB 28.069 MiB 29.29 MiB 30.511 MiB 31.732 MiB 32.952 MiB 34.173 MiB 36.394 MiB 37.614 MiB 38.835 MiB 40.056 MiB 41.276 MiB 42.497 MiB 43.718 MiB 45.651 MiB 46.871 MiB 48.092 MiB 49.313 MiB 50.533 MiB 51.754 MiB 52.975 MiB 54.196 MiB 55.416 MiB 56.637 MiB 57.858 MiB 59.078 MiB 60.299 MiB 61.52 MiB 62.74 MiB Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4096 bytes) in /in/UpmHK on line 16
Process exited with code 255.
Output for 7.2.0 - 7.2.33
0.371 MiB 1.661 MiB 2.96 MiB 4.196 MiB 5.735 MiB 6.971 MiB 8.207 MiB 9.871 MiB 11.107 MiB 12.343 MiB 13.756 MiB 14.992 MiB 16.228 MiB 17.464 MiB 19.378 MiB 20.614 MiB 21.85 MiB 23.264 MiB 24.5 MiB 25.736 MiB 27.15 MiB 28.386 MiB 29.622 MiB 30.858 MiB 32.272 MiB 33.508 MiB 34.744 MiB 37.158 MiB 38.394 MiB 39.63 MiB 41.044 MiB 42.28 MiB 43.516 MiB 44.752 MiB 46.166 MiB 47.402 MiB 48.638 MiB 50.051 MiB 51.287 MiB 52.523 MiB 53.937 MiB 55.173 MiB 56.409 MiB 57.645 MiB 59.059 MiB 60.295 MiB 61.531 MiB 62.945 MiB Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /in/UpmHK on line 9
Process exited with code 255.

preferences:
94.1 ms | 402 KiB | 73 Q