3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allowed_operators = array("*", "/", "^", "+", "-"); $rpn = "3 4 5 * -"; $rpnlen = strlen($rpn) - 1; $stack = array(); function digit($char) { return ctype_digit((string)$char); } //set_time_limit(2); function r_old() { global $pos, $rpn, $rpnlen, $stack, $allowed_operators, $result; if($rpnlen <= $pos) return false; $pos++; if($rpn[$pos] != ' ') { $tmp = ""; if(digit($rpn[$pos])) { while(digit($rpn[$pos]) || $rpn[$pos] == ".") { $tmp .= $rpn[$pos]; $pos++; } $pos--; if (!empty($tmp)) array_push($stack, $tmp); } else if(in_array($rpn[$pos], $allowed_operators)) { $second = array_pop($stack); $first = array_pop($stack); if($rpn[$pos] == '^') $result = eval("return pow($first, $second);"); else $result = eval("return ($first $rpn[$pos] $second);"); array_push($stack, $result); return r_old(); } else { return r_old(); } } return r_old(); } $result = 0; $pos = 0; function r() { global $pos, $rpn, $rpnlen, $allowed_operators, $result, $stack; while($rpn[$pos] == ' ') $pos++; if($rpnlen <= $pos) return false; if(digit($rpn[$pos])) { $tmp = ""; do { $tmp .= $rpn[$pos]; $pos++; } while(digit($rpn[$pos]) || $rpn[$pos] == "."); array_push($stack, $tmp); } else if(in_array($rpn[$pos], $allowed_operators)) { $second = array_pop($stack); $first = array_pop($stack); if($rpn[$pos] == '^') $result = eval("return pow($first, $second);"); else $result = eval("return ($first $rpn[$pos] $second);"); //echo "return ($first $rpn[$pos] $second);"; array_push($stack, $result); } $pos++; return r(); } r(); //echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Iibk
function name:  (null)
number of ops:  11
compiled vars:  !0 = $allowed_operators, !1 = $rpn, !2 = $rpnlen, !3 = $stack, !4 = $result, !5 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, '3+4+5+%2A+-'
    7     2        STRLEN                                           ~8      !1
          3        SUB                                              ~9      ~8, 1
          4        ASSIGN                                                   !2, ~9
    9     5        ASSIGN                                                   !3, <array>
   51     6        ASSIGN                                                   !4, 0
   52     7        ASSIGN                                                   !5, 0
   84     8        INIT_FCALL                                               'r'
          9        DO_FCALL                                      0          
   85    10      > RETURN                                                   1

Function digit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4Iibk
function name:  digit
number of ops:  7
compiled vars:  !0 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'ctype_digit'
          2        CAST                                          6  ~1      !0
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   13     6*     > RETURN                                                   null

End of function digit

Function r_old:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 87
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 41
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 20
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
Branch analysis from position: 31
Branch analysis from position: 31
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 84
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 66
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
filename:       /in/4Iibk
function name:  r_old
number of ops:  91
compiled vars:  !0 = $pos, !1 = $rpn, !2 = $rpnlen, !3 = $stack, !4 = $allowed_operators, !5 = $result, !6 = $tmp, !7 = $second, !8 = $first
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   BIND_GLOBAL                                              !0, 'pos'
          1        BIND_GLOBAL                                              !1, 'rpn'
          2        BIND_GLOBAL                                              !2, 'rpnlen'
          3        BIND_GLOBAL                                              !3, 'stack'
          4        BIND_GLOBAL                                              !4, 'allowed_operators'
          5        BIND_GLOBAL                                              !5, 'result'
   20     6        IS_SMALLER_OR_EQUAL                                      !2, !0
          7      > JMPZ                                                     ~9, ->9
          8    > > RETURN                                                   <false>
   22     9    >   PRE_INC                                                  !0
   23    10        FETCH_DIM_R                                      ~11     !1, !0
         11        IS_NOT_EQUAL                                             ~11, '+'
         12      > JMPZ                                                     ~12, ->87
   24    13    >   ASSIGN                                                   !6, ''
   26    14        INIT_FCALL                                               'digit'
         15        FETCH_DIM_R                                      ~14     !1, !0
         16        SEND_VAL                                                 ~14
         17        DO_FCALL                                      0  $15     
         18      > JMPZ                                                     $15, ->41
   27    19    > > JMP                                                      ->23
   28    20    >   FETCH_DIM_R                                      ~16     !1, !0
         21        ASSIGN_OP                                     8          !6, ~16
   29    22        PRE_INC                                                  !0
   27    23    >   INIT_FCALL                                               'digit'
         24        FETCH_DIM_R                                      ~19     !1, !0
         25        SEND_VAL                                                 ~19
         26        DO_FCALL                                      0  $20     
         27      > JMPNZ_EX                                         ~21     $20, ->31
         28    >   FETCH_DIM_R                                      ~22     !1, !0
         29        IS_EQUAL                                         ~23     ~22, '.'
         30        BOOL                                             ~21     ~23
         31    > > JMPNZ                                                    ~21, ->20
   31    32    >   PRE_DEC                                                  !0
   32    33        ISSET_ISEMPTY_CV                                 ~25     !6
         34        BOOL_NOT                                         ~26     ~25
         35      > JMPZ                                                     ~26, ->40
   33    36    >   INIT_FCALL                                               'array_push'
         37        SEND_REF                                                 !3
         38        SEND_VAR                                                 !6
         39        DO_ICALL                                                 
         40    > > JMP                                                      ->87
   34    41    >   INIT_FCALL                                               'in_array'
         42        FETCH_DIM_R                                      ~28     !1, !0
         43        SEND_VAL                                                 ~28
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                         $29     
         46      > JMPZ                                                     $29, ->84
   35    47    >   INIT_FCALL                                               'array_pop'
         48        SEND_REF                                                 !3
         49        DO_ICALL                                         $30     
         50        ASSIGN                                                   !7, $30
         51        INIT_FCALL                                               'array_pop'
         52        SEND_REF                                                 !3
         53        DO_ICALL                                         $32     
         54        ASSIGN                                                   !8, $32
   37    55        FETCH_DIM_R                                      ~34     !1, !0
         56        IS_EQUAL                                                 ~34, '%5E'
         57      > JMPZ                                                     ~35, ->66
   38    58    >   ROPE_INIT                                     5  ~37     'return+pow%28'
         59        ROPE_ADD                                      1  ~37     ~37, !8
         60        ROPE_ADD                                      2  ~37     ~37, '%2C+'
         61        ROPE_ADD                                      3  ~37     ~37, !7
         62        ROPE_END                                      4  ~36     ~37, '%29%3B'
         63        INCLUDE_OR_EVAL                                  $40     ~36, EVAL
         64        ASSIGN                                                   !5, $40
         65      > JMP                                                      ->76
   40    66    >   ROPE_INIT                                     7  ~44     'return+%28'
         67        ROPE_ADD                                      1  ~44     ~44, !8
         68        ROPE_ADD                                      2  ~44     ~44, '+'
         69        FETCH_DIM_R                                      ~42     !1, !0
         70        ROPE_ADD                                      3  ~44     ~44, ~42
         71        ROPE_ADD                                      4  ~44     ~44, '+'
         72        ROPE_ADD                                      5  ~44     ~44, !7
         73        ROPE_END                                      6  ~43     ~44, '%29%3B'
         74        INCLUDE_OR_EVAL                                  $48     ~43, EVAL
         75        ASSIGN                                                   !5, $48
   42    76    >   INIT_FCALL                                               'array_push'
         77        SEND_REF                                                 !3
         78        SEND_VAR                                                 !5
         79        DO_ICALL                                                 
   43    80        INIT_FCALL_BY_NAME                                       'r_old'
         81        DO_FCALL                                      0  $51     
         82      > RETURN                                                   $51
         83*       JMP                                                      ->87
   46    84    >   INIT_FCALL_BY_NAME                                       'r_old'
         85        DO_FCALL                                      0  $52     
         86      > RETURN                                                   $52
   49    87    >   INIT_FCALL_BY_NAME                                       'r_old'
         88        DO_FCALL                                      0  $53     
         89      > RETURN                                                   $53
   50    90*     > RETURN                                                   null

End of function r_old

Function r:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 7
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 37
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 31
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 76
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 62
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 76
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 7
Branch analysis from position: 11
Branch analysis from position: 7
filename:       /in/4Iibk
function name:  r
number of ops:  81
compiled vars:  !0 = $pos, !1 = $rpn, !2 = $rpnlen, !3 = $allowed_operators, !4 = $result, !5 = $stack, !6 = $tmp, !7 = $second, !8 = $first
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   BIND_GLOBAL                                              !0, 'pos'
          1        BIND_GLOBAL                                              !1, 'rpn'
          2        BIND_GLOBAL                                              !2, 'rpnlen'
          3        BIND_GLOBAL                                              !3, 'allowed_operators'
          4        BIND_GLOBAL                                              !4, 'result'
          5        BIND_GLOBAL                                              !5, 'stack'
   56     6      > JMP                                                      ->8
   57     7    >   PRE_INC                                                  !0
   56     8    >   FETCH_DIM_R                                      ~10     !1, !0
          9        IS_EQUAL                                                 ~10, '+'
         10      > JMPNZ                                                    ~11, ->7
   59    11    >   IS_SMALLER_OR_EQUAL                                      !2, !0
         12      > JMPZ                                                     ~12, ->14
         13    > > RETURN                                                   <false>
   61    14    >   INIT_FCALL                                               'digit'
         15        FETCH_DIM_R                                      ~13     !1, !0
         16        SEND_VAL                                                 ~13
         17        DO_FCALL                                      0  $14     
         18      > JMPZ                                                     $14, ->37
   62    19    >   ASSIGN                                                   !6, ''
   64    20    >   FETCH_DIM_R                                      ~16     !1, !0
         21        ASSIGN_OP                                     8          !6, ~16
   65    22        PRE_INC                                                  !0
   67    23        INIT_FCALL                                               'digit'
         24        FETCH_DIM_R                                      ~19     !1, !0
         25        SEND_VAL                                                 ~19
         26        DO_FCALL                                      0  $20     
         27      > JMPNZ_EX                                         ~21     $20, ->31
         28    >   FETCH_DIM_R                                      ~22     !1, !0
         29        IS_EQUAL                                         ~23     ~22, '.'
         30        BOOL                                             ~21     ~23
         31    > > JMPNZ                                                    ~21, ->20
   69    32    >   INIT_FCALL                                               'array_push'
         33        SEND_REF                                                 !5
         34        SEND_VAR                                                 !6
         35        DO_ICALL                                                 
         36      > JMP                                                      ->76
   70    37    >   INIT_FCALL                                               'in_array'
         38        FETCH_DIM_R                                      ~25     !1, !0
         39        SEND_VAL                                                 ~25
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $26     
         42      > JMPZ                                                     $26, ->76
   71    43    >   INIT_FCALL                                               'array_pop'
         44        SEND_REF                                                 !5
         45        DO_ICALL                                         $27     
         46        ASSIGN                                                   !7, $27
         47        INIT_FCALL                                               'array_pop'
         48        SEND_REF                                                 !5
         49        DO_ICALL                                         $29     
         50        ASSIGN                                                   !8, $29
   73    51        FETCH_DIM_R                                      ~31     !1, !0
         52        IS_EQUAL                                                 ~31, '%5E'
         53      > JMPZ                                                     ~32, ->62
   74    54    >   ROPE_INIT                                     5  ~34     'return+pow%28'
         55        ROPE_ADD                                      1  ~34     ~34, !8
         56        ROPE_ADD                                      2  ~34     ~34, '%2C+'
         57        ROPE_ADD                                      3  ~34     ~34, !7
         58        ROPE_END                                      4  ~33     ~34, '%29%3B'
         59        INCLUDE_OR_EVAL                                  $37     ~33, EVAL
         60        ASSIGN                                                   !4, $37
         61      > JMP                                                      ->72
   76    62    >   ROPE_INIT                                     7  ~41     'return+%28'
         63        ROPE_ADD                                      1  ~41     ~41, !8
         64        ROPE_ADD                                      2  ~41     ~41, '+'
         65        FETCH_DIM_R                                      ~39     !1, !0
         66        ROPE_ADD                                      3  ~41     ~41, ~39
         67        ROPE_ADD                                      4  ~41     ~41, '+'
         68        ROPE_ADD                                      5  ~41     ~41, !7
         69        ROPE_END                                      6  ~40     ~41, '%29%3B'
         70        INCLUDE_OR_EVAL                                  $45     ~40, EVAL
         71        ASSIGN                                                   !4, $45
   79    72    >   INIT_FCALL                                               'array_push'
         73        SEND_REF                                                 !5
         74        SEND_VAR                                                 !4
         75        DO_ICALL                                                 
   81    76    >   PRE_INC                                                  !0
   82    77        INIT_FCALL_BY_NAME                                       'r'
         78        DO_FCALL                                      0  $49     
         79      > RETURN                                                   $49
   83    80*     > RETURN                                                   null

End of function r

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
203.26 ms | 1418 KiB | 26 Q