Files
php-src/ext/reflection/tests/ReflectionMethod_double_construct_closure.phpt
Ilia Alshanetsky 87f8d17426 Free previous state when re-calling Reflection*::__construct()
ReflectionMethod::__construct() overwrote intern->ptr without releasing
the previous Closure::__invoke() trampoline, and
ReflectionClassConstant::__construct() overwrote the $name and $class
slots without dropping their previous references. ReflectionFunction,
ReflectionParameter and ReflectionProperty already release prior state
on re-entry.

Closes GH-22968
2026-07-31 11:39:17 -04:00

29 lines
528 B
PHP

--TEST--
ReflectionMethod double construct call on Closure::__invoke() does not leak
--FILE--
<?php
function test(ReflectionMethod $r) {
$r->__construct(function () {}, '__invoke');
}
$r = new ReflectionMethod(function () {}, '__invoke');
for ($i = 0; $i < 10; $i++) {
test($r);
}
$before = memory_get_usage();
for ($i = 0; $i < 1000; $i++) {
test($r);
}
$after = memory_get_usage();
var_dump($before === $after);
var_dump($r->name, $r->class);
?>
--EXPECT--
bool(true)
string(8) "__invoke"
string(7) "Closure"