You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lazy Objects: GH-15999: Object is released during initialization
3
+
--FILE--
4
+
<?php
5
+
6
+
class C {
7
+
public$s;
8
+
publicfunction__destruct() {
9
+
var_dump(__METHOD__);
10
+
}
11
+
}
12
+
13
+
print"# Ghost:\n";
14
+
15
+
$r = newReflectionClass(C::class);
16
+
17
+
$o = $r->newLazyGhost(function ($obj) {
18
+
global$o;
19
+
$o = null;
20
+
});
21
+
22
+
try {
23
+
$o->s = $o;
24
+
} catch (Error$e) {
25
+
printf("%s: %s\n", $e::class, $e->getMessage());
26
+
}
27
+
28
+
print"# Proxy:\n";
29
+
30
+
$o = $r->newLazyProxy(function ($obj) {
31
+
global$o;
32
+
$o = null;
33
+
returnnewC();
34
+
});
35
+
36
+
try {
37
+
$o->s = $o;
38
+
} catch (Error$e) {
39
+
printf("%s: %s\n", $e::class, $e->getMessage());
40
+
}
41
+
42
+
print"# GC cycle:\n";
43
+
44
+
$o = $r->newLazyGhost(function ($obj) {
45
+
global$o;
46
+
$o->s = $o;
47
+
$o = null;
48
+
gc_collect_cycles();
49
+
});
50
+
51
+
$o->s = $o;
52
+
gc_collect_cycles();
53
+
54
+
print"# Nested error (ghost):\n";
55
+
56
+
$r = newReflectionClass(C::class);
57
+
58
+
$o = $r->newLazyGhost(function ($obj) {
59
+
global$o;
60
+
$o = null;
61
+
returnnewstdClass;
62
+
});
63
+
64
+
try {
65
+
$o->s = $o;
66
+
} catch (Error$e) {
67
+
do {
68
+
printf("%s: %s\n", $e::class, $e->getMessage());
69
+
} while ($e = $e->getPrevious());
70
+
}
71
+
72
+
print"# Nested error (proxy):\n";
73
+
74
+
$r = newReflectionClass(C::class);
75
+
76
+
$o = $r->newLazyProxy(function ($obj) {
77
+
global$o;
78
+
$o = null;
79
+
returnnewstdClass;
80
+
});
81
+
82
+
try {
83
+
$o->s = $o;
84
+
} catch (Error$e) {
85
+
do {
86
+
printf("%s: %s\n", $e::class, $e->getMessage());
87
+
} while ($e = $e->getPrevious());
88
+
}
89
+
90
+
?>
91
+
==DONE==
92
+
--EXPECT--
93
+
# Ghost:
94
+
string(13) "C::__destruct"
95
+
Error: Lazy object was released during initialization
96
+
# Proxy:
97
+
string(13) "C::__destruct"
98
+
Error: Lazy object was released during initialization
99
+
# GC cycle:
100
+
string(13) "C::__destruct"
101
+
# Nested error (ghost):
102
+
Error: Lazy object was released during initialization
103
+
TypeError: Lazy object initializer must return NULL or no value
104
+
# Nested error (proxy):
105
+
Error: Lazy object was released during initialization
106
+
TypeError: The real instance class stdClass is not compatible with the proxy class C. The proxy must be a instance of the same class as the real instance, or a sub-class with no additional properties, and no overrides of the __destructor or __clone methods.
0 commit comments