3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface IDBResult { function FetchAssoc(); function Rewind(); function NumRows(); } 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; } function NumRows() { return count($this->_records); } } class ResultIterator implements Iterator { private $_rs; private $_rec = false; 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() { var_dump(__FUNCTION__); return call_user_func_array($this->_onLoad, array($this->_rec, $this->_index)); } public function key() { var_dump(__FUNCTION__); return $this->_index; } public function next() { var_dump(__FUNCTION__); $this->_index++; $this->_rec = $this->_rs->FetchAssoc(); } public function rewind() { var_dump(__FUNCTION__); $this->_index = 0; $this->_rs->Rewind(); } public function valid() { var_dump(__FUNCTION__); return $this->_index < $this->_rs->NumRows(); } } $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/R7ChU
function name:  (null)
number of ops:  17
compiled vars:  !0 = $rs, !1 = $it, !2 = $rec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'dbresult'
   27     1        DECLARE_CLASS                                            'resultiterator'
   68     2        NEW                                              $3      'DBResult'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   69     5        NEW                                              $6      'ResultIterator'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   70     9      > FE_RESET_R                                       $9      !1, ->15
         10    > > FE_FETCH_R                                               $9, !2, ->15
   71    11    >   INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   70    14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $9
   72    16      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FR7ChU%3A36%241

Class IDBResult:
Function fetchassoc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R7ChU
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/R7ChU
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

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

End of function numrows

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/R7ChU
function name:  FetchAssoc
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   POST_INC_OBJ                                     ~1      '_i'
          1        FETCH_OBJ_R                                      ~0      '_records'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3      > RETURN                                                   ~2
   18     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/R7ChU
function name:  Rewind
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN_OBJ                                               '_i'
          1        OP_DATA                                                  0
   21     2      > RETURN                                                   null

End of function rewind

Function numrows:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R7ChU
function name:  NumRows
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                      ~0      '_records'
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   24     3*     > RETURN                                                   null

End of function numrows

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/R7ChU
function name:  __construct
number of ops:  10
compiled vars:  !0 = $rs, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   35     2        ASSIGN_OBJ                                               '_rs'
          3        OP_DATA                                                  !0
   36     4        JMP_SET                                          ~4      !1, ->7
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR7ChU%3A36%241'
          6        QM_ASSIGN                                        ~4      ~5
          7        ASSIGN_OBJ                                               '_onLoad'
          8        OP_DATA                                                  ~4
   37     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/R7ChU
function name:  current
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'current'
          2        DO_ICALL                                                 
   41     3        FETCH_OBJ_R                                      ~1      '_onLoad'
          4        INIT_USER_CALL                                0          'call_user_func_array', ~1
          5        FETCH_OBJ_R                                      ~2      '_rec'
          6        INIT_ARRAY                                       ~3      ~2
          7        FETCH_OBJ_R                                      ~4      '_index'
          8        ADD_ARRAY_ELEMENT                                ~3      ~4
          9        SEND_ARRAY                                               ~3
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      0  $5      
         12      > RETURN                                                   $5
   42    13*     > 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/R7ChU
function name:  key
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'key'
          2        DO_ICALL                                                 
   46     3        FETCH_OBJ_R                                      ~1      '_index'
          4      > RETURN                                                   ~1
   47     5*     > 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/R7ChU
function name:  next
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'next'
          2        DO_ICALL                                                 
   51     3        PRE_INC_OBJ                                              '_index'
   52     4        FETCH_OBJ_R                                      ~3      '_rs'
          5        INIT_METHOD_CALL                                         ~3, 'FetchAssoc'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN_OBJ                                               '_rec'
          8        OP_DATA                                                  $4
   53     9      > 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/R7ChU
function name:  rewind
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'rewind'
          2        DO_ICALL                                                 
   57     3        ASSIGN_OBJ                                               '_index'
          4        OP_DATA                                                  0
   58     5        FETCH_OBJ_R                                      ~2      '_rs'
          6        INIT_METHOD_CALL                                         ~2, 'Rewind'
          7        DO_FCALL                                      0          
   59     8      > 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/R7ChU
function name:  valid
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'valid'
          2        DO_ICALL                                                 
   63     3        FETCH_OBJ_R                                      ~1      '_index'
          4        FETCH_OBJ_R                                      ~2      '_rs'
          5        INIT_METHOD_CALL                                         ~2, 'NumRows'
          6        DO_FCALL                                      0  $3      
          7        IS_SMALLER                                       ~4      ~1, $3
          8      > RETURN                                                   ~4
   64     9*     > RETURN                                                   null

End of function valid

End of class ResultIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.45 ms | 1400 KiB | 17 Q