3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generator_to_array(\Generator $generator) { $yielded = iterator_to_array($generator); return [ 'yielded' => $yielded, 'returned' => $generator->getReturn(), ]; } class test { private $whatever = false; public function __construct() { $a = generator_to_array($this->firstIterator()); $b = generator_to_array($this->secondIterator($this->firstIterator())); $c = generator_to_array($this->thirdIterator($this->firstIterator())); $this->whatever = true; $d = generator_to_array($this->firstIterator()); $e = generator_to_array($this->secondIterator($this->firstIterator())); $f = generator_to_array($this->thirdIterator($this->firstIterator())); var_dump([$a, $b, $c, $d, $e, $f]); } public function firstIterator(): \Iterator { yield 'a'=> 1; yield 'b'=> 2; yield 'c'=> 3; } public function secondIterator(\Iterator $first): \Iterator { if ($this->whatever === true) { return $first; } foreach($first as $key=>$value) { yield $key => $value * $value; } } public function thirdIterator(\Iterator $first): \Iterator { if ($this->whatever === true) { return $first; } return $this->thirdSubIterator($first); } public function thirdSubIterator(\Iterator $first): \Iterator { foreach($first as $key=>$value) { yield $key => $value * $value; } } } new test();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bQJkN
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   NEW                                              $0      'test'
          1        DO_FCALL                                      0          
          2        FREE                                                     $0
          3      > RETURN                                                   1

Function generator_to_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bQJkN
function name:  generator_to_array
number of ops:  11
compiled vars:  !0 = $generator, !1 = $yielded
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'iterator_to_array'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
    6     5        INIT_ARRAY                                       ~4      !1, 'yielded'
    7     6        INIT_METHOD_CALL                                         !0, 'getReturn'
          7        DO_FCALL                                      0  $5      
          8        ADD_ARRAY_ELEMENT                                ~4      $5, 'returned'
          9      > RETURN                                                   ~4
    9    10*     > RETURN                                                   null

End of function generator_to_array

Class test:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bQJkN
function name:  __construct
number of ops:  60
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d, !4 = $e, !5 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'generator_to_array'
          1        INIT_METHOD_CALL                                         'firstIterator'
          2        DO_FCALL                                      0  $6      
          3        SEND_VAR                                                 $6
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !0, $7
   18     6        INIT_FCALL                                               'generator_to_array'
          7        INIT_METHOD_CALL                                         'secondIterator'
          8        INIT_METHOD_CALL                                         'firstIterator'
          9        DO_FCALL                                      0  $9      
         10        SEND_VAR_NO_REF_EX                                       $9
         11        DO_FCALL                                      0  $10     
         12        SEND_VAR                                                 $10
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !1, $11
   19    15        INIT_FCALL                                               'generator_to_array'
         16        INIT_METHOD_CALL                                         'thirdIterator'
         17        INIT_METHOD_CALL                                         'firstIterator'
         18        DO_FCALL                                      0  $13     
         19        SEND_VAR_NO_REF_EX                                       $13
         20        DO_FCALL                                      0  $14     
         21        SEND_VAR                                                 $14
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !2, $15
   21    24        ASSIGN_OBJ                                               'whatever'
         25        OP_DATA                                                  <true>
   22    26        INIT_FCALL                                               'generator_to_array'
         27        INIT_METHOD_CALL                                         'firstIterator'
         28        DO_FCALL                                      0  $18     
         29        SEND_VAR                                                 $18
         30        DO_FCALL                                      0  $19     
         31        ASSIGN                                                   !3, $19
   23    32        INIT_FCALL                                               'generator_to_array'
         33        INIT_METHOD_CALL                                         'secondIterator'
         34        INIT_METHOD_CALL                                         'firstIterator'
         35        DO_FCALL                                      0  $21     
         36        SEND_VAR_NO_REF_EX                                       $21
         37        DO_FCALL                                      0  $22     
         38        SEND_VAR                                                 $22
         39        DO_FCALL                                      0  $23     
         40        ASSIGN                                                   !4, $23
   24    41        INIT_FCALL                                               'generator_to_array'
         42        INIT_METHOD_CALL                                         'thirdIterator'
         43        INIT_METHOD_CALL                                         'firstIterator'
         44        DO_FCALL                                      0  $25     
         45        SEND_VAR_NO_REF_EX                                       $25
         46        DO_FCALL                                      0  $26     
         47        SEND_VAR                                                 $26
         48        DO_FCALL                                      0  $27     
         49        ASSIGN                                                   !5, $27
   26    50        INIT_FCALL                                               'var_dump'
         51        INIT_ARRAY                                       ~29     !0
         52        ADD_ARRAY_ELEMENT                                ~29     !1
         53        ADD_ARRAY_ELEMENT                                ~29     !2
         54        ADD_ARRAY_ELEMENT                                ~29     !3
         55        ADD_ARRAY_ELEMENT                                ~29     !4
         56        ADD_ARRAY_ELEMENT                                ~29     !5
         57        SEND_VAL                                                 ~29
         58        DO_ICALL                                                 
   27    59      > RETURN                                                   null

End of function __construct

Function firstiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/bQJkN
function name:  firstIterator
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   GENERATOR_CREATE                                         
   31     1        YIELD                                                    1, 'a'
   32     2        YIELD                                                    2, 'b'
   33     3        YIELD                                                    3, 'c'
   34     4      > GENERATOR_RETURN                                         

End of function firstiterator

Function seconditerator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
filename:       /in/bQJkN
function name:  secondIterator
number of ops:  14
compiled vars:  !0 = $first, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   38     2        FETCH_OBJ_R                                      ~3      'whatever'
          3        TYPE_CHECK                                    8          ~3
          4      > JMPZ                                                     ~4, ->6
   40     5    > > GENERATOR_RETURN                                         
   43     6    > > FE_RESET_R                                       $5      !0, ->12
          7    > > FE_FETCH_R                                       ~6      $5, !1, ->12
          8    >   ASSIGN                                                   !2, ~6
   45     9        MUL                                              ~8      !1, !1
         10        YIELD                                                    ~8, !2
   43    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $5
   47    13      > GENERATOR_RETURN                                         

End of function seconditerator

Function thirditerator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bQJkN
function name:  thirdIterator
number of ops:  13
compiled vars:  !0 = $first
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        FETCH_OBJ_R                                      ~1      'whatever'
          2        TYPE_CHECK                                    8          ~1
          3      > JMPZ                                                     ~2, ->6
   53     4    >   VERIFY_RETURN_TYPE                                       !0
          5      > RETURN                                                   !0
   56     6    >   INIT_METHOD_CALL                                         'thirdSubIterator'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $3      
          9        VERIFY_RETURN_TYPE                                       $3
         10      > RETURN                                                   $3
   57    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function thirditerator

Function thirdsubiterator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
filename:       /in/bQJkN
function name:  thirdSubIterator
number of ops:  10
compiled vars:  !0 = $first, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   61     2      > FE_RESET_R                                       $3      !0, ->8
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->8
          4    >   ASSIGN                                                   !2, ~4
   63     5        MUL                                              ~6      !1, !1
          6        YIELD                                                    ~6, !2
   61     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $3
   65     9      > GENERATOR_RETURN                                         

End of function thirdsubiterator

End of class test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.4 ms | 1411 KiB | 23 Q