1--TEST--
2Fibers in destructors 011: gc collection after the dtor fiber is dtor
3--FILE--
4<?php
5
6class SimpleCycle {
7    public $self;
8    public function __construct() {
9        $this->self = $this;
10    }
11    public function __destruct() {
12        printf("%s\n", __METHOD__);
13    }
14}
15
16class CreateGarbageInDtor {
17    public $self;
18    public function __construct() {
19        $this->self = $this;
20    }
21    public function __destruct() {
22        printf("%s\n", __METHOD__);
23        // Create an object whose dtor will be called after the dtor fiber's
24        new CollectCyclesInFiberInDtor();
25    }
26}
27
28class CollectCyclesInFiberInDtor {
29    public $self;
30    public function __construct() {
31        $this->self = $this;
32    }
33    public function __destruct() {
34        printf("%s\n", __METHOD__);
35        new SimpleCycle();
36        print "Collecting cycles\n";
37        $f = new Fiber(function () {
38            gc_collect_cycles();
39        });
40        $f->start();
41        print "Done collecting cycles\n";
42    }
43}
44
45register_shutdown_function(function () {
46    print "Shutdown\n";
47});
48
49// Create a cycle
50new SimpleCycle();
51
52// Collect cycles to create the dtor fiber
53$f = new Fiber(function () {
54    gc_collect_cycles();
55});
56$f->start();
57
58// Create an object whose dtor will be called during shutdown
59// (by zend_objects_store_call_destructors)
60new CreateGarbageInDtor();
61
62?>
63--EXPECT--
64SimpleCycle::__destruct
65Shutdown
66CreateGarbageInDtor::__destruct
67CollectCyclesInFiberInDtor::__destruct
68Collecting cycles
69SimpleCycle::__destruct
70Done collecting cycles
71