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 = 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 !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/7DJVG
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'
   64     2        NEW                                              $3      'DBResult'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   65     5        NEW                                              $6      'ResultIterator'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   66     9      > FE_RESET_R                                       $9      !1, ->15
         10    > > FE_FETCH_R                                               $9, !2, ->15
   67    11    >   INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   66    14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $9
   68    16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F7DJVG%3A32%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7DJVG
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%2F7DJVG%3A32%241

Class IDBResult:
Function fetchassoc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7DJVG
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/7DJVG
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/7DJVG
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/7DJVG
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/7DJVG
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%2F7DJVG%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/7DJVG
function name:  current
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'current'
          2        DO_ICALL                                                 
   37     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
   38    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/7DJVG
function name:  key
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'key'
          2        DO_ICALL                                                 
   42     3        FETCH_OBJ_R                                      ~1      '_index'
          4      > RETURN                                                   ~1
   43     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/7DJVG
function name:  next
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'next'
          2        DO_ICALL                                                 
   47     3        PRE_INC_OBJ                                              '_index'
   48     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
   49     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/7DJVG
function name:  rewind
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'rewind'
          2        DO_ICALL                                                 
   53     3        ASSIGN_OBJ                                               '_index'
          4        OP_DATA                                                  0
   54     5        FETCH_OBJ_R                                      ~2      '_rs'
          6        INIT_METHOD_CALL                                         ~2, 'Rewind'
          7        DO_FCALL                                      0          
   55     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/7DJVG
function name:  valid
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'valid'
          2        DO_ICALL                                                 
   59     3        FETCH_OBJ_R                                      ~1      '_rec'
          4        TYPE_CHECK                                    2  ~2      ~1
          5        BOOL_NOT                                         ~3      ~2
          6      > RETURN                                                   ~3
   60     7*     > RETURN                                                   null

End of function valid

End of class ResultIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.95 ms | 1400 KiB | 17 Q