1--TEST-- 2Fibers in destructors 007: scope 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 function __destruct() { 13 $id = self::$counter++; 14 printf("%d: Start destruct\n", $id); 15 switch ($id) { 16 case 0: 17 global $f2; 18 $f2 = Fiber::getCurrent(); 19 Fiber::suspend(new stdClass); 20 break; 21 case 1: 22 $f3 = new Fiber(function () use ($id) { 23 printf("%d: Fiber\n", $id); 24 }); 25 $f3->start(); 26 break; 27 case 2: 28 global $f2; 29 $f2->resume(); 30 break; 31 } 32 printf("%d: End destruct\n", $id); 33 } 34} 35 36$f = new Fiber(function () { 37 new Cycle(); 38}); 39 40$f->start(); 41 42new Cycle(); 43new Cycle(); 44 45?> 46--EXPECT-- 470: Start destruct 481: Start destruct 491: Fiber 501: End destruct 512: Start destruct 520: End destruct 532: End destruct 54Shutdown 55