3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class MyIterator implements Iterator { private $var = array(); public function __construct($array) { if (is_array($array)) { $this->var = $array; } } public function rewind() { echo "rewinding\n"; reset($this->var); } public function current() { $var = current($this->var); echo "current: $var\n"; return $var; } public function key() { $var = key($this->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; } } $values = array(1,2,3); $it = new MyIterator($values); foreach ($it as $a => $b) { print "$a: $b\n"; } var_dump($it->value()) ?>
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
Jump found. Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
Jump found. Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 17
Jump found. Position 1 = -2
Branch analysis from position: 17
filename:       /in/uivDo
function name:  (null)
number of ops:  24
compiled vars:  !0 = $values, !1 = $it, !2 = $b, !3 = $a
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   DECLARE_CLASS                                    $4      '%00myiterator%2Fin%2FuivDo0x7f7e9fe9735a', 'myiterator'
         1        ADD_INTERFACE                                            $4, 'Iterator'
         2        VERIFY_ABSTRACT_CLASS                                    $4
  50     3        ASSIGN                                                   !0, <array>
  51     4        NEW                                              $6      :-1
         5        SEND_VAR_EX                                              !0
         6        DO_FCALL                                      0          
         7        ASSIGN                                                   !1, $6
  53     8      > FE_RESET_R                                       $9      !1, ->17
         9    > > FE_FETCH_R                                       ~10     $9, !2, ->17
        10    >   ASSIGN                                                   !3, ~10
  54    11        ROPE_INIT                                     4  ~13     !3
        12        ROPE_ADD                                      1  ~13     ~13, '%3A+'
        13        ROPE_ADD                                      2  ~13     ~13, !2
        14        ROPE_END                                      3  ~12     ~13, '%0A'
        15        ECHO                                                     ~12
        16      > JMP                                                      ->9
        17    >   FE_FREE                                                  $9
  56    18        INIT_FCALL                                               'var_dump'
        19        INIT_METHOD_CALL                                         !1, 'value'
        20        DO_FCALL                                      0  $15     
        21        SEND_VAR                                                 $15
        22        DO_ICALL                                                 
        23      > RETURN                                                   1

Class MyIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
Jump found. Position 1 = -2
Branch analysis from position: 5
filename:       /in/uivDo
function name:  __construct
number of ops:  6
compiled vars:  !0 = $array
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   6     0  E >   RECV                                             !0      
   8     1        TYPE_CHECK                                    7  ~1      !0
         2      > JMPZ                                                     ~1, ->5
   9     3    >   ASSIGN_OBJ                                               'var'
         4        OP_DATA                                                  !0
  11     5    > > RETURN                                                   null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/uivDo
function name:  rewind
number of ops:  6
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  15     0  E >   ECHO                                                     'rewinding%0A'
  16     1        INIT_FCALL                                               'reset'
         2        FETCH_OBJ_W                                      $0      'var'
         3        SEND_REF                                                 $0
         4        DO_ICALL                                                 
  17     5      > RETURN                                                   null

End of function rewind

Function current:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/uivDo
function name:  current
number of ops:  11
compiled vars:  !0 = $var
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  21     0  E >   INIT_FCALL                                               'current'
         1        FETCH_OBJ_R                                      $1      'var'
         2        SEND_VAR                                                 $1
         3        DO_ICALL                                         $2      
         4        ASSIGN                                                   !0, $2
  22     5        ROPE_INIT                                     3  ~5      'current%3A+'
         6        ROPE_ADD                                      1  ~5      ~5, !0
         7        ROPE_END                                      2  ~4      ~5, '%0A'
         8        ECHO                                                     ~4
  23     9      > RETURN                                                   !0
  24    10*     > RETURN                                                   null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/uivDo
function name:  key
number of ops:  11
compiled vars:  !0 = $var
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  28     0  E >   INIT_FCALL                                               'key'
         1        FETCH_OBJ_R                                      $1      'var'
         2        SEND_VAR                                                 $1
         3        DO_ICALL                                         $2      
         4        ASSIGN                                                   !0, $2
  29     5        ROPE_INIT                                     3  ~5      'key%3A+'
         6        ROPE_ADD                                      1  ~5      ~5, !0
         7        ROPE_END                                      2  ~4      ~5, '%0A'
         8        ECHO                                                     ~4
  30     9      > RETURN                                                   !0
  31    10*     > RETURN                                                   null

End of function key

Function next:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/uivDo
function name:  next
number of ops:  11
compiled vars:  !0 = $var
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  35     0  E >   INIT_FCALL                                               'next'
         1        FETCH_OBJ_W                                      $1      'var'
         2        SEND_REF                                                 $1
         3        DO_ICALL                                         $2      
         4        ASSIGN                                                   !0, $2
  36     5        ROPE_INIT                                     3  ~5      'next%3A+'
         6        ROPE_ADD                                      1  ~5      ~5, !0
         7        ROPE_END                                      2  ~4      ~5, '%0A'
         8        ECHO                                                     ~4
  37     9      > RETURN                                                   !0
  38    10*     > RETURN                                                   null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
Jump found. Position 1 = -2
Branch analysis from position: 9
filename:       /in/uivDo
function name:  valid
number of ops:  16
compiled vars:  !0 = $key, !1 = $var
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  42     0  E >   INIT_FCALL                                               'key'
         1        FETCH_OBJ_R                                      $2      'var'
         2        SEND_VAR                                                 $2
         3        DO_ICALL                                         $3      
         4        ASSIGN                                                   !0, $3
  43     5        IS_NOT_IDENTICAL                                 ~5      !0, null
         6      > JMPZ_EX                                          ~5      ~5, ->9
         7    >   IS_NOT_IDENTICAL                                 ~6      !0, <false>
         8        BOOL                                             ~5      ~6
         9    >   ASSIGN                                                   !1, ~5
  44    10        ROPE_INIT                                     3  ~9      'valid%3A+'
        11        ROPE_ADD                                      1  ~9      ~9, !1
        12        ROPE_END                                      2  ~8      ~9, '%0A'
        13        ECHO                                                     ~8
  45    14      > RETURN                                                   !1
  46    15*     > RETURN                                                   null

End of function valid

End of class MyIterator.

Generated using Vulcan Logic Dumper, using php 7.2.0