3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Gen implements Iterator { private $myArray; public function __construct( $n ) { $this->myArray = range(0,$n-1); } function rewind() { return reset($this->myArray); } function current() { return current($this->myArray); } function key() { return key($this->myArray); } function next() { return next($this->myArray); } function valid() { return key($this->myArray) !== null; } function destructor(){ return 'Drained!'; } } $gen = new Gen(3); // iterable object can be used in foreach foreach ($gen as $g) { echo $gen->current(); // sequentially making data available } $gen->next(); $gen->current();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/vY99h
function name:  (null)
number of ops:  17
compiled vars:  !0 = $gen, !1 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'gen'
   31     1        NEW                                              $2      'Gen'
          2        SEND_VAL_EX                                              3
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   34     5      > FE_RESET_R                                       $5      !0, ->11
          6    > > FE_FETCH_R                                               $5, !1, ->11
   35     7    >   INIT_METHOD_CALL                                         !0, 'current'
          8        DO_FCALL                                      0  $6      
          9        ECHO                                                     $6
   34    10      > JMP                                                      ->6
         11    >   FE_FREE                                                  $5
   37    12        INIT_METHOD_CALL                                         !0, 'next'
         13        DO_FCALL                                      0          
   38    14        INIT_METHOD_CALL                                         !0, 'current'
         15        DO_FCALL                                      0          
         16      > RETURN                                                   1

Class Gen:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vY99h
function name:  __construct
number of ops:  9
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 0
          3        SUB                                              ~2      !0, 1
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        ASSIGN_OBJ                                               'myArray'
          7        OP_DATA                                                  $3
    8     8      > RETURN                                                   null

End of function __construct

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

End of function rewind

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

End of function current

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

End of function key

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

End of function next

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

End of function valid

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

End of function destructor

End of class Gen.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.05 ms | 1396 KiB | 23 Q