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