3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyIterator implements Iterator { private $var = array(1,2,3); private $current; 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]; } if ($name == 'test') { $class = get_called_class(); return $this->var[$name] = (new $class())->$name(); } } public function many() { $a = array(88,99,11); return $a[1]; } public function rewind() { 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"; 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(); } } $it = new foo(); foreach ($it as $a => $b) { echo PHP_EOL . $it->test . PHP_EOL . PHP_EOL; print "$a: $b\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/a1Zom
function name:  (null)
number of ops:  21
compiled vars:  !0 = $it, !1 = $b, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'myiterator'
   81     1        DECLARE_CLASS                                            'foo', 'myiterator'
   88     2        NEW                                              $3      'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   90     5      > FE_RESET_R                                       $6      !0, ->19
          6    > > FE_FETCH_R                                       ~7      $6, !1, ->19
          7    >   ASSIGN                                                   !2, ~7
   91     8        FETCH_OBJ_R                                      ~9      !0, 'test'
          9        CONCAT                                           ~10     '%0A', ~9
         10        CONCAT                                           ~11     ~10, '%0A'
         11        CONCAT                                           ~12     ~11, '%0A'
         12        ECHO                                                     ~12
   92    13        ROPE_INIT                                     4  ~14     !2
         14        ROPE_ADD                                      1  ~14     ~14, '%3A+'
         15        ROPE_ADD                                      2  ~14     ~14, !1
         16        ROPE_END                                      3  ~13     ~14, '%0A'
         17        ECHO                                                     ~13
   90    18      > JMP                                                      ->6
         19    >   FE_FREE                                                  $6
   93    20      > 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/a1Zom
function name:  __construct
number of ops:  6
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      null
   11     1        TYPE_CHECK                                  128          !0
          2      > JMPZ                                                     ~1, ->5
   12     3    >   ASSIGN_OBJ                                               'var'
          4        OP_DATA                                                  !0
   14     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/a1Zom
function name:  __set
number of ops:  7
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        FETCH_OBJ_W                                      $2      'var'
          3        ASSIGN_DIM                                       ~3      $2, !0
          4        OP_DATA                                                  !1
          5      > RETURN                                                   ~3
   19     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
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a1Zom
function name:  __get
number of ops:  21
compiled vars:  !0 = $name, !1 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_IS                                     ~2      'var'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          3      > JMPZ                                                     ~3, ->7
   24     4    >   FETCH_OBJ_R                                      ~4      'var'
          5        FETCH_DIM_R                                      ~5      ~4, !0
          6      > RETURN                                                   ~5
   27     7    >   IS_EQUAL                                                 !0, 'test'
          8      > JMPZ                                                     ~6, ->20
   28     9    >   GET_CALLED_CLASS                                 ~7      
         10        ASSIGN                                                   !1, ~7
   29    11        FETCH_CLASS                                   0  $11     !1
         12        NEW                                              $12     $11
         13        DO_FCALL                                      0          
         14        INIT_METHOD_CALL                                         $12, !0
         15        DO_FCALL                                      0  $14     
         16        FETCH_OBJ_W                                      $9      'var'
         17        ASSIGN_DIM                                       ~10     $9, !0
         18        OP_DATA                                                  $14
         19      > RETURN                                                   ~10
   31    20    > > RETURN                                                   null

End of function __get

Function many:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a1Zom
function name:  many
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   37     1        FETCH_DIM_R                                      ~2      !0, 1
          2      > RETURN                                                   ~2
   38     3*     > RETURN                                                   null

End of function many

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a1Zom
function name:  rewind
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ECHO                                                     'rewinding%0A'
   44     1        INIT_FCALL                                               'reset'
          2        FETCH_OBJ_W                                      $0      'var'
          3        SEND_REF                                                 $0
          4        DO_ICALL                                                 
   45     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/a1Zom
function name:  current
number of ops:  13
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~1      'var'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   50     5        ASSIGN_OBJ                                               'current'
          6        OP_DATA                                                  !0
   51     7        ROPE_INIT                                     3  ~6      'current%3A+'
          8        ROPE_ADD                                      1  ~6      ~6, !0
          9        ROPE_END                                      2  ~5      ~6, '%0A'
         10        ECHO                                                     ~5
   52    11      > RETURN                                                   !0
   53    12*     > 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/a1Zom
function name:  key
number of ops:  13
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~1      'var'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   58     5        ASSIGN_OBJ                                               'key'
          6        OP_DATA                                                  !0
   59     7        ROPE_INIT                                     3  ~6      'key%3A+'
          8        ROPE_ADD                                      1  ~6      ~6, !0
          9        ROPE_END                                      2  ~5      ~6, '%0A'
         10        ECHO                                                     ~5
   60    11      > RETURN                                                   !0
   61    12*     > 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/a1Zom
function name:  next
number of ops:  11
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $1      'var'
          2        SEND_REF                                                 $1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   66     5        ROPE_INIT                                     3  ~5      'next%3A+'
          6        ROPE_ADD                                      1  ~5      ~5, !0
          7        ROPE_END                                      2  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   67     9      > RETURN                                                   !0
   68    10*     > 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/a1Zom
function name:  valid
number of ops:  16
compiled vars:  !0 = $key, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~2      'var'
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   73     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
   74    10        ROPE_INIT                                     3  ~9      'valid%3A+'
         11        ROPE_ADD                                      1  ~9      ~9, !1
         12        ROPE_END                                      2  ~8      ~9, '%0A'
         13        ECHO                                                     ~8
   75    14      > RETURN                                                   !1
   76    15*     > 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/a1Zom
function name:  test
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   INIT_METHOD_CALL                                         'many'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   85     3*     > RETURN                                                   null

End of function test

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.13 ms | 1400 KiB | 21 Q