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