3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Odometer { public function __construct(array $values, $max_places = 0){ $this->values = array_values($values); $this->max_places = $max_places; reset($values); $this->register[0] = key($values); end($values); $this->limit = key($values); } public function iterate($force = false){ $rollback = $this->register; $this->register[0]++; for($i = 0; $i < count($this->register); $i++){ if($this->register[$i] > $this->limit){ $this->register[$i] = 0; if(isset($this->register[$i+1])){ $this->register[$i+1]++; } else { if($this->max_places && count($this->register)+1 > $this->max_places && !$force){ $this->register = $rollback; return; } $this->register[$i+1] = 0; } } } } public function setMeter(){ for($i = 0; $i < count($this->register); $i++){ $this->meter[$i] = $this->values[$this->register[$i]]; } } public function readMeter(){ $this->setMeter(); return '[' . implode('][', array_reverse($this->meter)) . ']' . "\n"; } } $o = new Odometer(range('a','c'), 2); echo $o->readMeter(); for($i = 0; $i < 20; $i++){ $o->iterate(false); echo $o->readMeter(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
filename:       /in/gT7Nq
function name:  (null)
number of ops:  24
compiled vars:  !0 = $o, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $2      'Odometer'
          1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 'a'
          3        SEND_VAL                                                 'c'
          4        DO_ICALL                                         $3      
          5        SEND_VAR_NO_REF_EX                                       $3
          6        SEND_VAL_EX                                              2
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $2
   48     9        INIT_METHOD_CALL                                         !0, 'readMeter'
         10        DO_FCALL                                      0  $6      
         11        ECHO                                                     $6
   49    12        ASSIGN                                                   !1, 0
         13      > JMP                                                      ->21
   50    14    >   INIT_METHOD_CALL                                         !0, 'iterate'
         15        SEND_VAL_EX                                              <false>
         16        DO_FCALL                                      0          
   51    17        INIT_METHOD_CALL                                         !0, 'readMeter'
         18        DO_FCALL                                      0  $9      
         19        ECHO                                                     $9
   49    20        PRE_INC                                                  !1
         21    >   IS_SMALLER                                               !1, 20
         22      > JMPNZ                                                    ~11, ->14
   52    23    > > RETURN                                                   1

Class Odometer:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gT7Nq
function name:  __construct
number of ops:  27
compiled vars:  !0 = $values, !1 = $max_places
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
    5     2        INIT_FCALL                                               'array_values'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN_OBJ                                               'values'
          6        OP_DATA                                                  $3
    6     7        ASSIGN_OBJ                                               'max_places'
          8        OP_DATA                                                  !1
    8     9        INIT_FCALL                                               'reset'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
    9    12        INIT_FCALL                                               'key'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $8      
         15        FETCH_OBJ_W                                      $6      'register'
         16        ASSIGN_DIM                                               $6, 0
         17        OP_DATA                                                  $8
   11    18        INIT_FCALL                                               'end'
         19        SEND_REF                                                 !0
         20        DO_ICALL                                                 
   12    21        INIT_FCALL                                               'key'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $11     
         24        ASSIGN_OBJ                                               'limit'
         25        OP_DATA                                                  $11
   13    26      > RETURN                                                   null

End of function __construct

Function iterate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 44
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
Branch analysis from position: 8
Branch analysis from position: 25
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 8
Branch analysis from position: 49
Branch analysis from position: 8
Branch analysis from position: 36
Branch analysis from position: 33
Branch analysis from position: 44
filename:       /in/gT7Nq
function name:  iterate
number of ops:  50
compiled vars:  !0 = $force, !1 = $rollback, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV_INIT                                        !0      <false>
   16     1        FETCH_OBJ_R                                      ~3      'register'
          2        ASSIGN                                                   !1, ~3
   17     3        FETCH_OBJ_RW                                     $5      'register'
          4        FETCH_DIM_RW                                     $6      $5, 0
          5        PRE_INC                                                  $6
   18     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->45
   19     8    >   FETCH_OBJ_R                                      ~9      'register'
          9        FETCH_DIM_R                                      ~10     ~9, !2
         10        FETCH_OBJ_R                                      ~11     'limit'
         11        IS_SMALLER                                               ~11, ~10
         12      > JMPZ                                                     ~12, ->44
   20    13    >   FETCH_OBJ_W                                      $13     'register'
         14        ASSIGN_DIM                                               $13, !2
         15        OP_DATA                                                  0
   21    16        ADD                                              ~16     !2, 1
         17        FETCH_OBJ_IS                                     ~15     'register'
         18        ISSET_ISEMPTY_DIM_OBJ                         0          ~15, ~16
         19      > JMPZ                                                     ~17, ->25
   22    20    >   ADD                                              ~19     !2, 1
         21        FETCH_OBJ_RW                                     $18     'register'
         22        FETCH_DIM_RW                                     $20     $18, ~19
         23        PRE_INC                                                  $20
         24      > JMP                                                      ->44
   24    25    >   FETCH_OBJ_R                                      ~22     'max_places'
         26      > JMPZ_EX                                          ~22     ~22, ->33
         27    >   FETCH_OBJ_R                                      ~23     'register'
         28        COUNT                                            ~24     ~23
         29        ADD                                              ~25     ~24, 1
         30        FETCH_OBJ_R                                      ~26     'max_places'
         31        IS_SMALLER                                       ~27     ~26, ~25
         32        BOOL                                             ~22     ~27
         33    > > JMPZ_EX                                          ~22     ~22, ->36
         34    >   BOOL_NOT                                         ~28     !0
         35        BOOL                                             ~22     ~28
         36    > > JMPZ                                                     ~22, ->40
   25    37    >   ASSIGN_OBJ                                               'register'
         38        OP_DATA                                                  !1
   26    39      > RETURN                                                   null
   28    40    >   ADD                                              ~31     !2, 1
         41        FETCH_OBJ_W                                      $30     'register'
         42        ASSIGN_DIM                                               $30, ~31
         43        OP_DATA                                                  0
   18    44    >   PRE_INC                                                  !2
         45    >   FETCH_OBJ_R                                      ~34     'register'
         46        COUNT                                            ~35     ~34
         47        IS_SMALLER                                               !2, ~35
         48      > JMPNZ                                                    ~36, ->8
   32    49    > > RETURN                                                   null

End of function iterate

Function setmeter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 2
Branch analysis from position: 14
Branch analysis from position: 2
filename:       /in/gT7Nq
function name:  setMeter
number of ops:  15
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->10
   36     2    >   FETCH_OBJ_R                                      ~5      'register'
          3        FETCH_DIM_R                                      ~6      ~5, !0
          4        FETCH_OBJ_R                                      ~4      'values'
          5        FETCH_DIM_R                                      ~7      ~4, ~6
          6        FETCH_OBJ_W                                      $2      'meter'
          7        ASSIGN_DIM                                               $2, !0
          8        OP_DATA                                                  ~7
   35     9        PRE_INC                                                  !0
         10    >   FETCH_OBJ_R                                      ~9      'register'
         11        COUNT                                            ~10     ~9
         12        IS_SMALLER                                               !0, ~10
         13      > JMPNZ                                                    ~11, ->2
   38    14    > > RETURN                                                   null

End of function setmeter

Function readmeter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gT7Nq
function name:  readMeter
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   INIT_METHOD_CALL                                         'setMeter'
          1        DO_FCALL                                      0          
   42     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%5D%5B'
          4        INIT_FCALL                                               'array_reverse'
          5        FETCH_OBJ_R                                      ~1      'meter'
          6        SEND_VAL                                                 ~1
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10        CONCAT                                           ~4      '%5B', $3
         11        CONCAT                                           ~5      ~4, '%5D'
         12        CONCAT                                           ~6      ~5, '%0A'
         13      > RETURN                                                   ~6
   43    14*     > RETURN                                                   null

End of function readmeter

End of class Odometer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.2 ms | 1408 KiB | 27 Q