3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iterator = new class implements \Iterator { private $values = [1, 2, 3]; private $key; public function current() { return current($this->values); } public function next() { next($this->values); } public function key() { return $this->key; } public function valid() { return current($this->values) !== false; } public function rewind() { echo "Rewinding\n"; reset($this->values); } }; $generator = (function () { yield 1; yield 2; yield 3; })(); $wrappedIterator = (function($iterator) { foreach ($iterator as $value) { yield $value; } })($iterator); function skipOne(\Iterator $iterator) { $iterator->next(); echo "Skipped one\n"; yield from $iterator; } echo "\nUsing skipOne(iterator):\n"; foreach (skipOne($iterator) as $value) { var_dump($value); } echo "\nUsing skipOne(generator):\n"; foreach (skipOne($generator) as $value) { var_dump($value); } echo "\nUsing skipOne(wrappedIterator):\n"; foreach(skipOne($wrappedIterator) as $value) { var_dump($value); } echo "\nUsing foreach(iterator):\n"; foreach($iterator as $value) { var_dump($value); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 45
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 45
Branch analysis from position: 34
Branch analysis from position: 23
filename:       /in/c2ode
function name:  (null)
number of ops:  55
compiled vars:  !0 = $iterator, !1 = $generator, !2 = $wrappedIterator, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_ANON_CLASS                               <unknown> 
          1        NEW                                              $5      $4
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   35     4        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
   40     5        INIT_DYNAMIC_CALL                                        ~8
          6        DO_FCALL                                      0  $9      
   35     7        ASSIGN                                                   !1, $9
   42     8        DECLARE_LAMBDA_FUNCTION                          ~11     [1]
   46     9        INIT_DYNAMIC_CALL                                        ~11
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $12     
   42    12        ASSIGN                                                   !2, $12
   56    13        ECHO                                                     '%0AUsing+skipOne%28iterator%29%3A%0A'
   57    14        INIT_FCALL                                               'skipone'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $14     
         17      > FE_RESET_R                                       $15     $14, ->23
         18    > > FE_FETCH_R                                               $15, !3, ->23
   58    19    >   INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                                 
   57    22      > JMP                                                      ->18
         23    >   FE_FREE                                                  $15
   61    24        ECHO                                                     '%0AUsing+skipOne%28generator%29%3A%0A'
   62    25        INIT_FCALL                                               'skipone'
         26        SEND_VAR                                                 !1
         27        DO_FCALL                                      0  $17     
         28      > FE_RESET_R                                       $18     $17, ->34
         29    > > FE_FETCH_R                                               $18, !3, ->34
   63    30    >   INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                                 
   62    33      > JMP                                                      ->29
         34    >   FE_FREE                                                  $18
   66    35        ECHO                                                     '%0AUsing+skipOne%28wrappedIterator%29%3A%0A'
   67    36        INIT_FCALL                                               'skipone'
         37        SEND_VAR                                                 !2
         38        DO_FCALL                                      0  $20     
         39      > FE_RESET_R                                       $21     $20, ->45
         40    > > FE_FETCH_R                                               $21, !3, ->45
   68    41    >   INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !3
         43        DO_ICALL                                                 
   67    44      > JMP                                                      ->40
         45    >   FE_FREE                                                  $21
   71    46        ECHO                                                     '%0AUsing+foreach%28iterator%29%3A%0A'
   72    47      > FE_RESET_R                                       $23     !0, ->53
         48    > > FE_FETCH_R                                               $23, !3, ->53
   73    49    >   INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !3
         51        DO_ICALL                                                 
   72    52      > JMP                                                      ->48
         53    >   FE_FREE                                                  $23
   74    54      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/c2ode
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   GENERATOR_CREATE                                         
   37     1        YIELD                                                    1
   38     2        YIELD                                                    2
   39     3        YIELD                                                    3
   40     4      > GENERATOR_RETURN                                         

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
filename:       /in/c2ode
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $iterator, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   43     2      > FE_RESET_R                                       $2      !0, ->6
          3    > > FE_FETCH_R                                               $2, !1, ->6
   44     4    >   YIELD                                                    !1
   43     5      > JMP                                                      ->3
          6    >   FE_FREE                                                  $2
   46     7      > GENERATOR_RETURN                                         

End of Dynamic Function 1

Function skipone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/c2ode
function name:  skipOne
number of ops:  8
compiled vars:  !0 = $iterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   51     2        INIT_METHOD_CALL                                         !0, 'next'
          3        DO_FCALL                                      0          
   52     4        ECHO                                                     'Skipped+one%0A'
   53     5        YIELD_FROM                                       ~2      !0
          6        FREE                                                     ~2
   54     7      > GENERATOR_RETURN                                         

End of function skipone

Class Iterator@anonymous:
Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c2ode
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~0      'values'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   11     5*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c2ode
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $0      'values'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                                 
   16     4      > RETURN                                                   null

End of function next

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c2ode
function name:  key
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      'key'
          1      > RETURN                                                   ~0
   21     2*     > RETURN                                                   null

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c2ode
function name:  valid
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~0      'values'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        TYPE_CHECK                                  1018  ~2      $1
          5      > RETURN                                                   ~2
   26     6*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c2ode
function name:  rewind
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ECHO                                                     'Rewinding%0A'
   31     1        INIT_FCALL                                               'reset'
          2        FETCH_OBJ_W                                      $0      'values'
          3        SEND_REF                                                 $0
          4        DO_ICALL                                                 
   32     5      > RETURN                                                   null

End of function rewind

End of class Iterator@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
134.57 ms | 1016 KiB | 20 Q