3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyIterator implements Iterator { private static $data; private $var = array(1,2,3); private $current; private $rewind; private $key; public function __construct($array = null) { if (is_array($array)) { $this->var = $array; } } public function __set($name, $value) { return $this->var[$name] = $value; } public function __get($name) { if (isset($this->var[$name])) { return $this->var[$name]; } } public function many() { if($this->rewind){ self::$data['many'] = array(88,99,11); } return self::$data['many'][$this->key]; } public function manys() { if($this->rewind){ self::$data['manys'] = array(55,66,77); } return self::$data['manys'][$this->key]; } public function rewind() { self::$data = null; $this->rewind = true; //echo "rewinding\n"; reset($this->var); } public function current() { $var = current($this->var); $this->current = $var; //echo "current: $var\n"; return $var; } public function key() { $var = key($this->var); $this->key = $var; //echo "key: $var\n"; return $var; } public function next() { $var = next($this->var); //echo "next: $var\n"; $this->rewind = false; return $var; } public function valid() { $key = key($this->var); $var = ($key !== NULL && $key !== FALSE); //echo "valid: $var\n"; return $var; } } class foo extends MyIterator{ public function test(){ return $this->many(); } public function test2(){ return $this->manys(); } } $it = new foo(); echo PHP_EOL . $it->test() . PHP_EOL . PHP_EOL; echo PHP_EOL . $it->test2() . PHP_EOL . PHP_EOL; $it = new foo(); foreach ($it as $a => $b) { echo PHP_EOL . $it->test() . PHP_EOL . PHP_EOL; echo PHP_EOL . $it->test2() . PHP_EOL . PHP_EOL; print "$a: $b\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 41
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 41
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/9T7hr
function name:  (null)
number of ops:  43
compiled vars:  !0 = $it, !1 = $b, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'myiterator'
   91     1        DECLARE_CLASS                                            'foo', 'myiterator'
  101     2        NEW                                              $3      'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
  103     5        INIT_METHOD_CALL                                         !0, 'test'
          6        DO_FCALL                                      0  $6      
          7        CONCAT                                           ~7      '%0A', $6
          8        CONCAT                                           ~8      ~7, '%0A'
          9        CONCAT                                           ~9      ~8, '%0A'
         10        ECHO                                                     ~9
  104    11        INIT_METHOD_CALL                                         !0, 'test2'
         12        DO_FCALL                                      0  $10     
         13        CONCAT                                           ~11     '%0A', $10
         14        CONCAT                                           ~12     ~11, '%0A'
         15        CONCAT                                           ~13     ~12, '%0A'
         16        ECHO                                                     ~13
  108    17        NEW                                              $14     'foo'
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !0, $14
  110    20      > FE_RESET_R                                       $17     !0, ->41
         21    > > FE_FETCH_R                                       ~18     $17, !1, ->41
         22    >   ASSIGN                                                   !2, ~18
  111    23        INIT_METHOD_CALL                                         !0, 'test'
         24        DO_FCALL                                      0  $20     
         25        CONCAT                                           ~21     '%0A', $20
         26        CONCAT                                           ~22     ~21, '%0A'
         27        CONCAT                                           ~23     ~22, '%0A'
         28        ECHO                                                     ~23
  112    29        INIT_METHOD_CALL                                         !0, 'test2'
         30        DO_FCALL                                      0  $24     
         31        CONCAT                                           ~25     '%0A', $24
         32        CONCAT                                           ~26     ~25, '%0A'
         33        CONCAT                                           ~27     ~26, '%0A'
         34        ECHO                                                     ~27
  113    35        ROPE_INIT                                     4  ~29     !2
         36        ROPE_ADD                                      1  ~29     ~29, '%3A+'
         37        ROPE_ADD                                      2  ~29     ~29, !1
         38        ROPE_END                                      3  ~28     ~29, '%0A'
         39        ECHO                                                     ~28
  110    40      > JMP                                                      ->21
         41    >   FE_FREE                                                  $17
  114    42      > RETURN                                                   1

Class MyIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/9T7hr
function name:  __construct
number of ops:  6
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV_INIT                                        !0      null
   13     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~1, ->5
   14     3    >   ASSIGN_OBJ                                               'var'
          4        OP_DATA                                                  !0
   16     5    > > RETURN                                                   null

End of function __construct

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9T7hr
function name:  __set
number of ops:  7
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        FETCH_OBJ_W                                      $2      'var'
          3        ASSIGN_DIM                                       ~3      $2, !0
          4        OP_DATA                                                  !1
          5      > RETURN                                                   ~3
   21     6*     > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9T7hr
function name:  __get
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        FETCH_OBJ_IS                                     ~1      'var'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
   26     4    >   FETCH_OBJ_R                                      ~3      'var'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   28     7    > > RETURN                                                   null

End of function __get

Function many:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/9T7hr
function name:  many
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'rewind'
          1      > JMPZ                                                     ~0, ->5
   34     2    >   FETCH_STATIC_PROP_W          unknown             $1      'data'
          3        ASSIGN_DIM                                               $1, 'many'
          4        OP_DATA                                                  <array>
   36     5    >   FETCH_OBJ_R                                      ~5      'key'
          6        FETCH_STATIC_PROP_R          unknown             ~3      'data'
          7        FETCH_DIM_R                                      ~4      ~3, 'many'
          8        FETCH_DIM_R                                      ~6      ~4, ~5
          9      > RETURN                                                   ~6
   37    10*     > RETURN                                                   null

End of function many

Function manys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/9T7hr
function name:  manys
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                      ~0      'rewind'
          1      > JMPZ                                                     ~0, ->5
   42     2    >   FETCH_STATIC_PROP_W          unknown             $1      'data'
          3        ASSIGN_DIM                                               $1, 'manys'
          4        OP_DATA                                                  <array>
   44     5    >   FETCH_OBJ_R                                      ~5      'key'
          6        FETCH_STATIC_PROP_R          unknown             ~3      'data'
          7        FETCH_DIM_R                                      ~4      ~3, 'manys'
          8        FETCH_DIM_R                                      ~6      ~4, ~5
          9      > RETURN                                                   ~6
   45    10*     > RETURN                                                   null

End of function manys

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9T7hr
function name:  rewind
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN_STATIC_PROP                                       'data'
          1        OP_DATA                                                  null
   51     2        ASSIGN_OBJ                                               'rewind'
          3        OP_DATA                                                  <true>
   53     4        INIT_FCALL                                               'reset'
          5        FETCH_OBJ_W                                      $2      'var'
          6        SEND_REF                                                 $2
          7        DO_ICALL                                                 
   54     8      > 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/9T7hr
function name:  current
number of ops:  9
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~1      'var'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   59     5        ASSIGN_OBJ                                               'current'
          6        OP_DATA                                                  !0
   61     7      > RETURN                                                   !0
   62     8*     > 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/9T7hr
function name:  key
number of ops:  9
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~1      'var'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   67     5        ASSIGN_OBJ                                               'key'
          6        OP_DATA                                                  !0
   69     7      > RETURN                                                   !0
   70     8*     > 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/9T7hr
function name:  next
number of ops:  9
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $1      'var'
          2        SEND_REF                                                 $1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   76     5        ASSIGN_OBJ                                               'rewind'
          6        OP_DATA                                                  <false>
   77     7      > RETURN                                                   !0
   78     8*     > RETURN                                                   null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/9T7hr
function name:  valid
number of ops:  12
compiled vars:  !0 = $key, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~2      'var'
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   83     5        TYPE_CHECK                                  1020  ~5      !0
          6      > JMPZ_EX                                          ~5      ~5, ->9
          7    >   TYPE_CHECK                                  1018  ~6      !0
          8        BOOL                                             ~5      ~6
          9    >   ASSIGN                                                   !1, ~5
   85    10      > RETURN                                                   !1
   86    11*     > RETURN                                                   null

End of function valid

End of class MyIterator.

Class foo:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9T7hr
function name:  test
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   INIT_METHOD_CALL                                         'many'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   95     3*     > RETURN                                                   null

End of function test

Function test2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9T7hr
function name:  test2
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   97     0  E >   INIT_METHOD_CALL                                         'manys'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   98     3*     > RETURN                                                   null

End of function test2

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.86 ms | 1412 KiB | 21 Q