3v4l.org

run code in 300+ PHP versions simultaneously
<?php function async(callable $call): Fiber { $fiber = new Fiber($call); $fiber->start(); return $fiber; } function all(Fiber ...$fibers): array { $all_terminated = function() use($fibers) { foreach($fibers as $fiber) { if (!$fiber->isTerminated()) { return false; } } return true; }; while(!$all_terminated()) { foreach($fibers as $fiber) { if($fiber->isSuspended()) { $fiber->resume(); } } } $res = []; foreach($fibers as $fiber) { $res[] = $fiber->getReturn(); } } function await(Fiber $fiber): mixed { while($fiber->isSuspended()) { $fiber->resume(); } return $fiber->getReturn(); } $a = async(function(): string { ob_start(); // v- called from layout.html.twig Fiber::suspend(); echo '<-- part 1 - layout -->'; return ob_get_clean(); }); $b = async(function(): string { ob_start(); // v- called from layout.html.twig Fiber::suspend(); echo '<-- part 2 - layout -->'; return ob_get_clean(); }); all($a, $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zchtr
function name:  (null)
number of ops:  15
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'async'
          1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   58     2        SEND_VAL                                                 ~2
   49     3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   60     5        INIT_FCALL                                               'async'
          6        DECLARE_LAMBDA_FUNCTION                          ~5      [1]
   69     7        SEND_VAL                                                 ~5
   60     8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
   71    10        INIT_FCALL                                               'all'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zchtr
function name:  {closure}
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                               'ob_start'
          1        DO_ICALL                                                 
   53     2        INIT_STATIC_METHOD_CALL                                  'Fiber', 'suspend'
          3        DO_FCALL                                      0          
   55     4        ECHO                                                     '%3C--+part+1+-+layout+--%3E'
   57     5        INIT_FCALL                                               'ob_get_clean'
          6        DO_ICALL                                         $2      
          7        VERIFY_RETURN_TYPE                                       $2
          8      > RETURN                                                   $2
   58     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zchtr
function name:  {closure}
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'ob_start'
          1        DO_ICALL                                                 
   64     2        INIT_STATIC_METHOD_CALL                                  'Fiber', 'suspend'
          3        DO_FCALL                                      0          
   66     4        ECHO                                                     '%3C--+part+2+-+layout+--%3E'
   68     5        INIT_FCALL                                               'ob_get_clean'
          6        DO_ICALL                                         $2      
          7        VERIFY_RETURN_TYPE                                       $2
          8      > RETURN                                                   $2
   69     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of Dynamic Function 1

Function async:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zchtr
function name:  async
number of ops:  11
compiled vars:  !0 = $call, !1 = $fiber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        NEW                                              $2      'Fiber'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
    6     5        INIT_METHOD_CALL                                         !1, 'start'
          6        DO_FCALL                                      0          
    8     7        VERIFY_RETURN_TYPE                                       !1
          8      > RETURN                                                   !1
    9     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function async

Function all:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 5
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 12
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 5
Branch analysis from position: 18
Branch analysis from position: 5
Branch analysis from position: 13
filename:       /in/Zchtr
function name:  all
number of ops:  29
compiled vars:  !0 = $fibers, !1 = $all_terminated, !2 = $fiber, !3 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV_VARIADIC                                    !0      
   15     1        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          2        BIND_LEXICAL                                             ~4, !0
          3        ASSIGN                                                   !1, ~4
   26     4      > JMP                                                      ->14
   27     5    > > FE_RESET_R                                       $6      !0, ->13
          6    > > FE_FETCH_R                                               $6, !2, ->13
   28     7    >   INIT_METHOD_CALL                                         !2, 'isSuspended'
          8        DO_FCALL                                      0  $7      
          9      > JMPZ                                                     $7, ->12
   29    10    >   INIT_METHOD_CALL                                         !2, 'resume'
         11        DO_FCALL                                      0          
   27    12    > > JMP                                                      ->6
         13    >   FE_FREE                                                  $6
   26    14    >   INIT_DYNAMIC_CALL                                        !1
         15        DO_FCALL                                      0  $9      
         16        BOOL_NOT                                         ~10     $9
         17      > JMPNZ                                                    ~10, ->5
   34    18    >   ASSIGN                                                   !3, <array>
   35    19      > FE_RESET_R                                       $12     !0, ->26
         20    > > FE_FETCH_R                                               $12, !2, ->26
   36    21    >   INIT_METHOD_CALL                                         !2, 'getReturn'
         22        DO_FCALL                                      0  $14     
         23        ASSIGN_DIM                                               !3
         24        OP_DATA                                                  $14
   35    25      > JMP                                                      ->20
         26    >   FE_FREE                                                  $12
   38    27        VERIFY_RETURN_TYPE                                       
         28      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/Zchtr
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $fibers, !1 = $fiber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   BIND_STATIC                                              !0
   16     1      > FE_RESET_R                                       $2      !0, ->10
          2    > > FE_FETCH_R                                               $2, !1, ->10
   17     3    >   INIT_METHOD_CALL                                         !1, 'isTerminated'
          4        DO_FCALL                                      0  $3      
          5        BOOL_NOT                                         ~4      $3
          6      > JMPZ                                                     ~4, ->9
   18     7    >   FE_FREE                                                  $2
          8      > RETURN                                                   <false>
   16     9    > > JMP                                                      ->2
         10    >   FE_FREE                                                  $2
   23    11      > RETURN                                                   <true>
   24    12*     > RETURN                                                   null

End of Dynamic Function 0

End of function all

Function await:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 2
Branch analysis from position: 7
Branch analysis from position: 2
filename:       /in/Zchtr
function name:  await
number of ops:  12
compiled vars:  !0 = $fiber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1      > JMP                                                      ->4
   43     2    >   INIT_METHOD_CALL                                         !0, 'resume'
          3        DO_FCALL                                      0          
   42     4    >   INIT_METHOD_CALL                                         !0, 'isSuspended'
          5        DO_FCALL                                      0  $2      
          6      > JMPNZ                                                    $2, ->2
   46     7    >   INIT_METHOD_CALL                                         !0, 'getReturn'
          8        DO_FCALL                                      0  $3      
          9      > RETURN                                                   $3
   47    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function await

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.01 ms | 1030 KiB | 18 Q