1--TEST--
2Fibers in destructors 001: Suspend in destructor
3--FILE--
4<?php
5
6register_shutdown_function(function () {
7    printf("Shutdown\n");
8});
9
10class Cycle {
11    public static $counter = 0;
12    public $self;
13    public function __construct() {
14        $this->self = $this;
15    }
16    public function __destruct() {
17        $id = self::$counter++;
18        printf("%d: Start destruct\n", $id);
19        if ($id === 0) {
20            global $f2;
21            $f2 = Fiber::getCurrent();
22            Fiber::suspend(new stdClass);
23        }
24        printf("%d: End destruct\n", $id);
25    }
26}
27
28$f = new Fiber(function () {
29    global $f2;
30    new Cycle();
31    new Cycle();
32    new Cycle();
33    new Cycle();
34    new Cycle();
35    gc_collect_cycles();
36    $f2->resume();
37});
38
39$f->start();
40
41?>
42--EXPECT--
430: Start destruct
441: Start destruct
451: End destruct
462: Start destruct
472: End destruct
483: Start destruct
493: End destruct
504: Start destruct
514: End destruct
520: End destruct
53Shutdown
54