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/gc_003.phpt
Arnaud Le Blanc 58aa6fc830 Lazy objects
RFC: https://wiki.php.net/rfc/lazy-objects

Closes GH-15019
2024-08-30 17:30:03 +02:00

60 lines
986 B
PHP

--TEST--
Lazy objects: GC 003
--FILE--
<?php
class Canary {
public $value;
public function __destruct() {
var_dump(__FUNCTION__);
}
}
class C {
}
function ghost() {
printf("# Ghost:\n");
$canary = new Canary();
$obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor();
(new ReflectionClass($obj))->resetAsLazyGhost($obj, function () use ($canary) {
});
$canary->value = $obj;
$obj = null;
$canary = null;
gc_collect_cycles();
}
function proxy() {
printf("# Proxy:\n");
$canary = new Canary();
$obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor();
(new ReflectionClass($obj))->resetAsLazyProxy($obj, function () use ($canary) {
return new C();
});
$canary->value = $obj;
$obj = null;
$canary = null;
gc_collect_cycles();
}
ghost();
proxy();
?>
==DONE==
--EXPECT--
# Ghost:
string(10) "__destruct"
# Proxy:
string(10) "__destruct"
==DONE==