3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Queue { private $queue = []; public function add($var) { $this->queue[] = $var; } public function take(): \Generator { while($var = array_shift($this->queue)) { if($var instanceof Queue) { yield from $var->take(); } else { yield $var; } } } } $subQueue = new Queue(); $subQueue->add('A'); $subQueue->add('B'); $subQueue->add('C'); $queue = new Queue(); $queue->add('a'); $queue->add('b'); $queue->add('c'); $queue->add($subQueue); $queue->add('d'); foreach($queue->take() as $index => $item) { echo $index; if($index === 1) { $queue->add('hello'); } var_dump($item); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 45
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 45
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 41
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/sIpXu
function name:  (null)
number of ops:  47
compiled vars:  !0 = $subQueue, !1 = $queue, !2 = $item, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $4      'Queue'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   23     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              'A'
          5        DO_FCALL                                      0          
   24     6        INIT_METHOD_CALL                                         !0, 'add'
          7        SEND_VAL_EX                                              'B'
          8        DO_FCALL                                      0          
   25     9        INIT_METHOD_CALL                                         !0, 'add'
         10        SEND_VAL_EX                                              'C'
         11        DO_FCALL                                      0          
   27    12        NEW                                              $10     'Queue'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $10
   28    15        INIT_METHOD_CALL                                         !1, 'add'
         16        SEND_VAL_EX                                              'a'
         17        DO_FCALL                                      0          
   29    18        INIT_METHOD_CALL                                         !1, 'add'
         19        SEND_VAL_EX                                              'b'
         20        DO_FCALL                                      0          
   30    21        INIT_METHOD_CALL                                         !1, 'add'
         22        SEND_VAL_EX                                              'c'
         23        DO_FCALL                                      0          
   31    24        INIT_METHOD_CALL                                         !1, 'add'
         25        SEND_VAR_EX                                              !0
         26        DO_FCALL                                      0          
   32    27        INIT_METHOD_CALL                                         !1, 'add'
         28        SEND_VAL_EX                                              'd'
         29        DO_FCALL                                      0          
   36    30        INIT_METHOD_CALL                                         !1, 'take'
         31        DO_FCALL                                      0  $18     
         32      > FE_RESET_R                                       $19     $18, ->45
         33    > > FE_FETCH_R                                       ~20     $19, !2, ->45
         34    >   ASSIGN                                                   !3, ~20
   37    35        ECHO                                                     !3
   38    36        IS_IDENTICAL                                             !3, 1
         37      > JMPZ                                                     ~22, ->41
   39    38    >   INIT_METHOD_CALL                                         !1, 'add'
         39        SEND_VAL_EX                                              'hello'
         40        DO_FCALL                                      0          
   41    41    >   INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !2
         43        DO_ICALL                                                 
   36    44      > JMP                                                      ->33
         45    >   FE_FREE                                                  $19
   42    46      > RETURN                                                   1

Class Queue:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sIpXu
function name:  add
number of ops:  5
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        FETCH_OBJ_W                                      $1      'queue'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
    9     4      > RETURN                                                   null

End of function add

Function take:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
Branch analysis from position: 2
filename:       /in/sIpXu
function name:  take
number of ops:  17
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   GENERATOR_CREATE                                         
   12     1      > JMP                                                      ->10
   13     2    >   INSTANCEOF                                               !0, 'Queue'
          3      > JMPZ                                                     ~1, ->9
   14     4    >   INIT_METHOD_CALL                                         !0, 'take'
          5        DO_FCALL                                      0  $2      
          6        YIELD_FROM                                       ~3      $2
          7        FREE                                                     ~3
   13     8      > JMP                                                      ->10
   16     9    >   YIELD                                                    !0
   12    10    >   INIT_FCALL                                               'array_shift'
         11        FETCH_OBJ_W                                      $5      'queue'
         12        SEND_REF                                                 $5
         13        DO_ICALL                                         $6      
         14        ASSIGN                                           ~7      !0, $6
         15      > JMPNZ                                                    ~7, ->2
   19    16    > > GENERATOR_RETURN                                         

End of function take

End of class Queue.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.14 ms | 1006 KiB | 15 Q