mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
60 lines
986 B
PHP
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==
|