xref: /PHP-8.4/Zend/tests/lazy_objects/gc_002.phpt (revision 58aa6fc8)
1--TEST--
2Lazy objects: GC 002
3--FILE--
4<?php
5
6class Canary {
7    public $value;
8    public function __destruct() {
9        var_dump(__FUNCTION__);
10    }
11}
12
13class C {
14}
15
16function ghost() {
17    printf("# Ghost:\n");
18
19    $canary = new Canary();
20
21    $obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor();
22    (new ReflectionClass($obj))->resetAsLazyGhost($obj, function () use ($canary) {
23    });
24
25    $canary->value = $obj;
26    $canary = null;
27    $obj = null;
28
29    gc_collect_cycles();
30}
31
32function proxy() {
33    printf("# Proxy:\n");
34
35    $canary = new Canary();
36
37    $obj = (new ReflectionClass(C::class))->newInstanceWithoutConstructor();
38    (new ReflectionClass($obj))->resetAsLazyProxy($obj, function () use ($canary) {
39        return new C();
40    });
41
42    $canary->value = $obj;
43    $canary = null;
44    $obj = null;
45
46    gc_collect_cycles();
47}
48
49ghost();
50proxy();
51
52?>
53==DONE==
54--EXPECT--
55# Ghost:
56string(10) "__destruct"
57# Proxy:
58string(10) "__destruct"
59==DONE==
60