<?php
// array_filter_short.php
namespace Somewhere\On\Earth;
class Foo {
function leaking(array $array) {
$f = function ($array) {
return \array_filter($array, fn($item) => !is_null($item));
};
for (;;) {
$clone = (array) $array;
$res = $f($clone);
printf("memory: %d\n", \memory_get_usage());
unset($clone, $res);
}
}
function run() {
$array = array_combine(range(1, 1000, 2), array_fill(1, 500, null));
$array += array_combine(range(2, 1000, 2), array_fill(1, 500, true));
$this->leaking($array);
}
}
(new Foo())->run();
I've experienced a memory leak using
array_filterwhen both opcahe and xhprof are enabled.here is a demo script:
Test it with
Here is the PHP bug I've filled
https://bugs.php.net/bug.php?id=81215