3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyIterator implements Iterator { public $var = array(1,2,3); public function __construct($array) { $var = array(1,2,3); 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; } } class MyCollection implements IteratorAggregate { private $count = 0; /* public function __construct($array) { $var = array(1,2,3); if (is_array($array)) { $this->var = $array; } } */ // Required definition of interface IteratorAggregate public function getIterator() { return new MyIterator($this->var); } public function add($value) { $this->var[$this->count++] = $value; } } /*$values = array('value 1','value 2','value 3');*/ $coll = new Mycollection(); $coll->add('value 1'); $coll->add('value 2'); $coll->add('value 3'); foreach ($coll as $key => $val) { echo "key/value: [$key -> $val]\n\n"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/qS4iY
function name:  (null)
number of ops:  26
compiled vars:  !0 = $coll, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'myiterator'
   52     1        DECLARE_CLASS                                            'mycollection'
   75     2        NEW                                              $3      'Mycollection'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   76     5        INIT_METHOD_CALL                                         !0, 'add'
          6        SEND_VAL_EX                                              'value+1'
          7        DO_FCALL                                      0          
   77     8        INIT_METHOD_CALL                                         !0, 'add'
          9        SEND_VAL_EX                                              'value+2'
         10        DO_FCALL                                      0          
   78    11        INIT_METHOD_CALL                                         !0, 'add'
         12        SEND_VAL_EX                                              'value+3'
         13        DO_FCALL                                      0          
   83    14      > FE_RESET_R                                       $9      !0, ->24
         15    > > FE_FETCH_R                                       ~10     $9, !1, ->24
         16    >   ASSIGN                                                   !2, ~10
   84    17        ROPE_INIT                                     5  ~13     'key%2Fvalue%3A+%5B'
         18        ROPE_ADD                                      1  ~13     ~13, !2
         19        ROPE_ADD                                      2  ~13     ~13, '+-%3E+'
         20        ROPE_ADD                                      3  ~13     ~13, !1
         21        ROPE_END                                      4  ~12     ~13, '%5D%0A%0A'
         22        ECHO                                                     ~12
   83    23      > JMP                                                      ->15
         24    >   FE_FREE                                                  $9
   86    25      > RETURN                                                   1

Class MyIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/qS4iY
function name:  __construct
number of ops:  7
compiled vars:  !0 = $array, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, <array>
    8     2        TYPE_CHECK                                  128          !0
          3      > JMPZ                                                     ~3, ->6
    9     4    >   ASSIGN_OBJ                                               'var'
          5        OP_DATA                                                  !0
   11     6    > > 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/qS4iY
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qS4iY
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_VAL                                                 ~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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qS4iY
function name:  key
number of ops:  11
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~1      'var'
          2        SEND_VAL                                                 ~1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   31     5        ROPE_INIT                                     3  ~5      'key%3A+'
          6        ROPE_ADD                                      1  ~5      ~5, !0
          7        ROPE_END                                      2  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   32     9      > RETURN                                                   !0
   33    10*     > 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/qS4iY
function name:  next
number of ops:  11
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $1      'var'
          2        SEND_REF                                                 $1
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   38     5        ROPE_INIT                                     3  ~5      'next%3A+'
          6        ROPE_ADD                                      1  ~5      ~5, !0
          7        ROPE_END                                      2  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   39     9      > RETURN                                                   !0
   40    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/qS4iY
function name:  valid
number of ops:  16
compiled vars:  !0 = $key, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~2      'var'
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   44     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
   45    10        ROPE_INIT                                     3  ~9      'valid%3A+'
         11        ROPE_ADD                                      1  ~9      ~9, !1
         12        ROPE_END                                      2  ~8      ~9, '%0A'
         13        ECHO                                                     ~8
   46    14      > RETURN                                                   !1
   47    15*     > RETURN                                                   null

End of function valid

End of class MyIterator.

Class MyCollection:
Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qS4iY
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   NEW                                              $0      'MyIterator'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      'var'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
          6*     > RETURN                                                   null

End of function getiterator

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

End of function add

End of class MyCollection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.47 ms | 1408 KiB | 21 Q