1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/lazy_objects/gh20657-001.phpt
Arnaud Le Blanc 6d6d013d79 Mark object non-lazy before deleting info in zend_lazy_object_realize()
A lazy object is marked non-lazy when all its properties are
initialized. Before doing so we delete the object info, resulting in a
temporarily invalid state. In GH-20657 the GC is triggered at this moment.

Fix by deleting the object info _after_ marking it non lazy.

Fixes GH-20657
Closes GH-21094
2026-02-03 11:48:36 +01:00

33 lines
553 B
PHP

--TEST--
GH-20657: GC during zend_lazy_object_realize()
--CREDITS--
vi3tL0u1s
--FILE--
<?php
class C {
public $a;
}
$reflector = new ReflectionClass(C::class);
for ($i = 0; $i < 10000; $i++) {
$obj = $reflector->newLazyGhost(function ($obj) {});
// Add to roots
$obj2 = $obj;
unset($obj2);
// Initialize all props to mark object non-lazy. Also create a cycle.
$reflector->getProperty('a')->setRawValueWithoutLazyInitialization($obj, $obj);
}
var_dump($obj);
?>
--EXPECTF--
object(C)#%d (1) {
["a"]=>
*RECURSION*
}