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