3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface IDBResult { function FetchAssoc(); function Rewind(); } class DBResult implements IDBResult { private $_records = array( array('abc' => 'def'), ); private $_i = 0; function FetchAssoc() { return $this->_records[$this->_i++]; } function Rewind() { $this->_i = 0; } } class ResultIterator implements Iterator { private $_rs; private $_rec; private $_index = 0; private $_onLoad; function __construct(IDBResult $rs, callable $callback = null) { $this->_rs = $rs; $this->_onLoad = $callback ?: function($rec, $i) { return $rec; }; } public function current() { return call_user_func_array($this->_onLoad, array($this->_rec, $this->_index)); } public function key() { return $this->_index; } public function next() { $this->_index++; $this->_rec = $this->_rs->FetchAssoc(); } public function rewind() { $this->_index = 0; $this->_rs->Rewind(); } public function valid() { return !is_null($this->_rec); } } $rs = new DBResult(); $it = new ResultIterator($rs); foreach($it as $rec) { print_r($rec); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/hg5hl
function name:  (null)
number of ops:  17
compiled vars:  !0 = $rs, !1 = $it, !2 = $rec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'dbresult'
   23     1        DECLARE_CLASS                                            'resultiterator'
   59     2        NEW                                              $3      'DBResult'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   60     5        NEW                                              $6      'ResultIterator'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   61     9      > FE_RESET_R                                       $9      !1, ->15
         10    > > FE_FETCH_R                                               $9, !2, ->15
   62    11    >   INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   61    14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $9
   63    16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fhg5hl%3A32%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $rec, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > RETURN                                                   !0
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fhg5hl%3A32%241

Class IDBResult:
Function fetchassoc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  FetchAssoc
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   null

End of function fetchassoc

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  Rewind
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   null

End of function rewind

End of class IDBResult.

Class DBResult:
Function fetchassoc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  FetchAssoc
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   POST_INC_OBJ                                     ~1      '_i'
          1        FETCH_OBJ_R                                      ~0      '_records'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3      > RETURN                                                   ~2
   17     4*     > RETURN                                                   null

End of function fetchassoc

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  Rewind
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN_OBJ                                               '_i'
          1        OP_DATA                                                  0
   20     2      > RETURN                                                   null

End of function rewind

End of class DBResult.

Class ResultIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  __construct
number of ops:  10
compiled vars:  !0 = $rs, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   31     2        ASSIGN_OBJ                                               '_rs'
          3        OP_DATA                                                  !0
   32     4        JMP_SET                                          ~4      !1, ->7
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fhg5hl%3A32%241'
          6        QM_ASSIGN                                        ~4      ~5
          7        ASSIGN_OBJ                                               '_onLoad'
          8        OP_DATA                                                  ~4
   33     9      > RETURN                                                   null

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  current
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                      ~0      '_onLoad'
          1        INIT_USER_CALL                                0          'call_user_func_array', ~0
          2        FETCH_OBJ_R                                      ~1      '_rec'
          3        INIT_ARRAY                                       ~2      ~1
          4        FETCH_OBJ_R                                      ~3      '_index'
          5        ADD_ARRAY_ELEMENT                                ~2      ~3
          6        SEND_ARRAY                                               ~2
          7        CHECK_UNDEF_ARGS                                         
          8        DO_FCALL                                      0  $4      
          9      > RETURN                                                   $4
   37    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/hg5hl
function name:  key
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   FETCH_OBJ_R                                      ~0      '_index'
          1      > RETURN                                                   ~0
   41     2*     > 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/hg5hl
function name:  next
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   PRE_INC_OBJ                                              '_index'
   45     1        FETCH_OBJ_R                                      ~2      '_rs'
          2        INIT_METHOD_CALL                                         ~2, 'FetchAssoc'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN_OBJ                                               '_rec'
          5        OP_DATA                                                  $3
   46     6      > RETURN                                                   null

End of function next

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  rewind
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   ASSIGN_OBJ                                               '_index'
          1        OP_DATA                                                  0
   50     2        FETCH_OBJ_R                                      ~1      '_rs'
          3        INIT_METHOD_CALL                                         ~1, 'Rewind'
          4        DO_FCALL                                      0          
   51     5      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg5hl
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~0      '_rec'
          1        TYPE_CHECK                                    2  ~1      ~0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
   55     4*     > RETURN                                                   null

End of function valid

End of class ResultIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.51 ms | 1404 KiB | 15 Q