xref: /PHP-8.1/Zend/tests/fibers/no-switch-gc.phpt (revision fdc22744)
1--TEST--
2Context switches are prevented during GC collect cycles
3--FILE--
4<?php
5
6$fiber = new Fiber(function () {
7    call_user_func(function () {
8        $a = new class () {};
9
10        $b = new class () {
11            public function __destruct() {
12                Fiber::suspend();
13            }
14        };
15
16        $a->next = $b;
17        $b->next = $a;
18    });
19
20    gc_collect_cycles();
21});
22
23$fiber->start();
24
25?>
26--EXPECTF--
27Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-gc.php:%d
28Stack trace:
29#0 %sno-switch-gc.php(%d): Fiber::suspend()
30#1 [internal function]: class@anonymous->__destruct()
31#2 %sno-switch-gc.php(%d): gc_collect_cycles()
32#3 [internal function]: {closure}()
33#4 %sno-switch-gc.php(%d): Fiber->start()
34#5 {main}
35  thrown in %sno-switch-gc.php on line %d
36