Files
php-src/ext/reflection/tests/ReflectionClassConstant_double_construct.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

34 lines
629 B
PHP

--TEST--
ReflectionClassConstant double construct call does not leak $name and $class
--FILE--
<?php
class C {
const FOO = 1;
}
function test(ReflectionClassConstant $r) {
/* implode() so that the name is not an interned string. */
$r->__construct(C::class, implode('', ['F', 'O', 'O']));
}
$r = new ReflectionClassConstant(C::class, 'FOO');
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(3) "FOO"
string(1) "C"