File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Fibers in destructors 009: Destructor resurrects object, suspends
3
+ --FILE--
4
+ <?php
5
+
6
+ register_shutdown_function (function () {
7
+ printf ("Shutdown \n" );
8
+ });
9
+
10
+ class Cycle {
11
+ public $ self ;
12
+ public function __construct () {
13
+ $ this ->self = $ this ;
14
+ }
15
+ public function __destruct () {
16
+ global $ ref , $ f2 ;
17
+ $ ref = $ this ;
18
+ $ f2 = Fiber::getCurrent ();
19
+ Fiber::suspend ();
20
+ }
21
+ }
22
+
23
+ $ f = new Fiber (function () {
24
+ global $ weakRef ;
25
+ $ weakRef = WeakReference::create (new Cycle ());
26
+ gc_collect_cycles ();
27
+ });
28
+
29
+ $ f ->start ();
30
+ var_dump ((bool ) $ weakRef ->get ());
31
+ gc_collect_cycles ();
32
+ $ f2 ->resume ();
33
+ gc_collect_cycles ();
34
+ var_dump ((bool ) $ weakRef ->get ());
35
+ ?>
36
+ --EXPECT--
37
+ bool(true)
38
+ bool(true)
39
+ Shutdown
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Fibers in destructors 010: Destructor resurrects object, suspends, unrefs
3
+ --FILE--
4
+ <?php
5
+
6
+ register_shutdown_function (function () {
7
+ printf ("Shutdown \n" );
8
+ });
9
+
10
+ class Cycle {
11
+ public $ self ;
12
+ public function __construct () {
13
+ $ this ->self = $ this ;
14
+ }
15
+ public function __destruct () {
16
+ global $ ref , $ f2 ;
17
+ $ ref = $ this ;
18
+ $ f2 = Fiber::getCurrent ();
19
+ Fiber::suspend ();
20
+ $ ref = null ;
21
+ }
22
+ }
23
+
24
+ $ f = new Fiber (function () {
25
+ global $ weakRef ;
26
+ $ weakRef = WeakReference::create (new Cycle ());
27
+ gc_collect_cycles ();
28
+ });
29
+
30
+ $ f ->start ();
31
+ var_dump ((bool ) $ weakRef ->get ());
32
+ gc_collect_cycles ();
33
+ $ f2 ->resume ();
34
+ gc_collect_cycles ();
35
+ var_dump ((bool ) $ weakRef ->get ());
36
+ ?>
37
+ --EXPECT--
38
+ bool(true)
39
+ bool(false)
40
+ Shutdown
You can’t perform that action at this time.
0 commit comments