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-002.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

44 lines
814 B
PHP

--TEST--
GH-20657 002: GC during zend_lazy_object_realize() - reset as lazy during realize()
--FILE--
<?php
class C {
public $a;
}
class D {
public $self;
public function __construct() {
$this->self = $this;
}
public function __destruct() {
global $obj, $reflector;
$reflector->resetAsLazyGhost($obj, function () {});
}
}
new D();
$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*
}