3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bc() { $argv = func_get_args(); $string = str_replace(' ', '', "({$argv[0]})"); $operations = array(); if (strpos($string, '^') !== false) $operations[] = '\^'; if (strpbrk($string, '*/%') !== false) $operations[] = '[\*\/\%]'; if (strpbrk($string, '+-') !== false) $operations[] = '[\+\-]'; if (strpbrk($string, '<>!=') !== false) $operations[] = '<|>|=|<=|==|>=|!=|<>'; $string = preg_replace('/\$([0-9\.]+)/e', '$argv[$1]', $string); while (preg_match('/\(([^\)\(]*)\)/', $string, $match)) { foreach ($operations as $operation) { if (preg_match("/([+-]{0,1}[0-9\.]+)($operation)([+-]{0,1}[0-9\.]+)/", $match[1], $m)) { switch($m[2]) { case '+': $result = bcadd($m[1], $m[3]); break; case '-': $result = bcsub($m[1], $m[3]); break; case '*': $result = bcmul($m[1], $m[3]); break; case '/': $result = bcdiv($m[1], $m[3]); break; case '%': $result = bcmod($m[1], $m[3]); break; case '^': $result = bcpow($m[1], $m[3]); break; case '==': case '=': $result = bccomp($m[1], $m[3]) == 0; break; case '>': $result = bccomp($m[1], $m[3]) == 1; break; case '<': $result = bccomp($m[1], $m[3]) == -1; break; case '>=': $result = bccomp($m[1], $m[3]) >= 0; break; case '<=': $result = bccomp($m[1], $m[3]) <= 0; break; case '<>': case '!=': $result = bccomp($m[1], $m[3]) != 0; break; } $match[1] = str_replace($m[0], $result, $match[1]); } } $string = str_replace($match[0], $match[1], $string); } return $string; } // Exemplo de uso: Operações matemáticas $resultado = bc("(2 + 3) * 4"); echo $resultado; // Saída: 20
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/geCrH
function name:  (null)
number of ops:  6
compiled vars:  !0 = $resultado
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'bc'
          1        SEND_VAL                                                 '%282+%2B+3%29+%2A+4'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   45     4        ECHO                                                     !0
          5      > RETURN                                                   1

Function bc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 241
Branch analysis from position: 241
2 jumps found. (Code = 44) Position 1 = 247, Position 2 = 52
Branch analysis from position: 247
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 232
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 232
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 231
Branch analysis from position: 64
16 jumps found. (Code = 188) Position 1 = 95, Position 2 = 105, Position 3 = 115, Position 4 = 125, Position 5 = 135, Position 6 = 145, Position 7 = 155, Position 8 = 155, Position 9 = 166, Position 10 = 177, Position 11 = 188, Position 12 = 199, Position 13 = 210, Position 14 = 210, Position 15 = 221, Position 16 = 66
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 105
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 125
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 135
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 145
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 155
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 155
Branch analysis from position: 166
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 177
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 188
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 199
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 210
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 210
Branch analysis from position: 221
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 95
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 105
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 115
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 74, Position 2 = 125
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 135
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 145
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 155
Branch analysis from position: 80
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 155
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 84, Position 2 = 166
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 177
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 188
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 199
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 92, Position 2 = 210
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 210
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 221
Branch analysis from position: 221
Branch analysis from position: 210
Branch analysis from position: 210
Branch analysis from position: 199
Branch analysis from position: 188
Branch analysis from position: 177
Branch analysis from position: 166
Branch analysis from position: 155
Branch analysis from position: 155
Branch analysis from position: 145
Branch analysis from position: 135
Branch analysis from position: 125
Branch analysis from position: 115
Branch analysis from position: 105
Branch analysis from position: 95
Branch analysis from position: 231
Branch analysis from position: 232
2 jumps found. (Code = 44) Position 1 = 247, Position 2 = 52
Branch analysis from position: 247
Branch analysis from position: 52
Branch analysis from position: 232
Branch analysis from position: 45
Branch analysis from position: 37
Branch analysis from position: 29
Branch analysis from position: 21
filename:       /in/geCrH
function name:  bc
number of ops:  249
compiled vars:  !0 = $argv, !1 = $string, !2 = $operations, !3 = $operation, !4 = $match, !5 = $m, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   FUNC_GET_ARGS                                    ~7      
          1        ASSIGN                                                   !0, ~7
    5     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '+'
          4        SEND_VAL                                                 ''
          5        ROPE_INIT                                     3  ~11     '%28'
          6        FETCH_DIM_R                                      ~9      !0, 0
          7        ROPE_ADD                                      1  ~11     ~11, ~9
          8        ROPE_END                                      2  ~10     ~11, '%29'
          9        SEND_VAL                                                 ~10
         10        DO_ICALL                                         $13     
         11        ASSIGN                                                   !1, $13
    7    12        ASSIGN                                                   !2, <array>
    8    13        INIT_FCALL                                               'strpos'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 '%5E'
         16        DO_ICALL                                         $16     
         17        TYPE_CHECK                                  1018          $16
         18      > JMPZ                                                     ~17, ->21
         19    >   ASSIGN_DIM                                               !2
         20        OP_DATA                                                  '%5C%5E'
    9    21    >   INIT_FCALL                                               'strpbrk'
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 '%2A%2F%25'
         24        DO_ICALL                                         $19     
         25        TYPE_CHECK                                  1018          $19
         26      > JMPZ                                                     ~20, ->29
         27    >   ASSIGN_DIM                                               !2
         28        OP_DATA                                                  '%5B%5C%2A%5C%2F%5C%25%5D'
   10    29    >   INIT_FCALL                                               'strpbrk'
         30        SEND_VAR                                                 !1
         31        SEND_VAL                                                 '%2B-'
         32        DO_ICALL                                         $22     
         33        TYPE_CHECK                                  1018          $22
         34      > JMPZ                                                     ~23, ->37
         35    >   ASSIGN_DIM                                               !2
         36        OP_DATA                                                  '%5B%5C%2B%5C-%5D'
   11    37    >   INIT_FCALL                                               'strpbrk'
         38        SEND_VAR                                                 !1
         39        SEND_VAL                                                 '%3C%3E%21%3D'
         40        DO_ICALL                                         $25     
         41        TYPE_CHECK                                  1018          $25
         42      > JMPZ                                                     ~26, ->45
         43    >   ASSIGN_DIM                                               !2
         44        OP_DATA                                                  '%3C%7C%3E%7C%3D%7C%3C%3D%7C%3D%3D%7C%3E%3D%7C%21%3D%7C%3C%3E'
   13    45    >   INIT_FCALL                                               'preg_replace'
         46        SEND_VAL                                                 '%2F%5C%24%28%5B0-9%5C.%5D%2B%29%2Fe'
         47        SEND_VAL                                                 '%24argv%5B%241%5D'
         48        SEND_VAR                                                 !1
         49        DO_ICALL                                         $28     
         50        ASSIGN                                                   !1, $28
   14    51      > JMP                                                      ->241
   15    52    > > FE_RESET_R                                       $30     !2, ->232
         53    > > FE_FETCH_R                                               $30, !3, ->232
   16    54    >   INIT_FCALL                                               'preg_match'
         55        ROPE_INIT                                     3  ~32     '%2F%28%5B%2B-%5D%7B0%2C1%7D%5B0-9%5C.%5D%2B%29%28'
         56        ROPE_ADD                                      1  ~32     ~32, !3
         57        ROPE_END                                      2  ~31     ~32, '%29%28%5B%2B-%5D%7B0%2C1%7D%5B0-9%5C.%5D%2B%29%2F'
         58        SEND_VAL                                                 ~31
         59        FETCH_DIM_R                                      ~34     !4, 1
         60        SEND_VAL                                                 ~34
         61        SEND_REF                                                 !5
         62        DO_ICALL                                         $35     
         63      > JMPZ                                                     $35, ->231
   17    64    >   FETCH_DIM_R                                      ~36     !5, 2
         65      > SWITCH_STRING                                            ~36, [ '%2B':->95, '-':->105, '%2A':->115, '%2F':->125, '%25':->135, '%5E':->145, '%3D%3D':->155, '%3D':->155, '%3E':->166, '%3C':->177, '%3E%3D':->188, '%3C%3D':->199, '%3C%3E':->210, '%21%3D':->210, ], ->221
   18    66    >   CASE                                                     ~36, '%2B'
         67      > JMPNZ                                                    ~37, ->95
   19    68    >   CASE                                                     ~36, '-'
         69      > JMPNZ                                                    ~37, ->105
   20    70    >   CASE                                                     ~36, '%2A'
         71      > JMPNZ                                                    ~37, ->115
   21    72    >   CASE                                                     ~36, '%2F'
         73      > JMPNZ                                                    ~37, ->125
   22    74    >   CASE                                                     ~36, '%25'
         75      > JMPNZ                                                    ~37, ->135
   23    76    >   CASE                                                     ~36, '%5E'
         77      > JMPNZ                                                    ~37, ->145
   24    78    >   CASE                                                     ~36, '%3D%3D'
         79      > JMPNZ                                                    ~37, ->155
   25    80    >   CASE                                                     ~36, '%3D'
         81      > JMPNZ                                                    ~37, ->155
   26    82    >   CASE                                                     ~36, '%3E'
         83      > JMPNZ                                                    ~37, ->166
   27    84    >   CASE                                                     ~36, '%3C'
         85      > JMPNZ                                                    ~37, ->177
   28    86    >   CASE                                                     ~36, '%3E%3D'
         87      > JMPNZ                                                    ~37, ->188
   29    88    >   CASE                                                     ~36, '%3C%3D'
         89      > JMPNZ                                                    ~37, ->199
   30    90    >   CASE                                                     ~36, '%3C%3E'
         91      > JMPNZ                                                    ~37, ->210
   31    92    >   CASE                                                     ~36, '%21%3D'
         93      > JMPNZ                                                    ~37, ->210
         94    > > JMP                                                      ->221
   18    95    >   INIT_FCALL_BY_NAME                                       'bcadd'
         96        CHECK_FUNC_ARG                                           
         97        FETCH_DIM_FUNC_ARG                               $38     !5, 1
         98        SEND_FUNC_ARG                                            $38
         99        CHECK_FUNC_ARG                                           
        100        FETCH_DIM_FUNC_ARG                               $39     !5, 3
        101        SEND_FUNC_ARG                                            $39
        102        DO_FCALL                                      0  $40     
        103        ASSIGN                                                   !6, $40
        104      > JMP                                                      ->221
   19   105    >   INIT_FCALL_BY_NAME                                       'bcsub'
        106        CHECK_FUNC_ARG                                           
        107        FETCH_DIM_FUNC_ARG                               $42     !5, 1
        108        SEND_FUNC_ARG                                            $42
        109        CHECK_FUNC_ARG                                           
        110        FETCH_DIM_FUNC_ARG                               $43     !5, 3
        111        SEND_FUNC_ARG                                            $43
        112        DO_FCALL                                      0  $44     
        113        ASSIGN                                                   !6, $44
        114      > JMP                                                      ->221
   20   115    >   INIT_FCALL_BY_NAME                                       'bcmul'
        116        CHECK_FUNC_ARG                                           
        117        FETCH_DIM_FUNC_ARG                               $46     !5, 1
        118        SEND_FUNC_ARG                                            $46
        119        CHECK_FUNC_ARG                                           
        120        FETCH_DIM_FUNC_ARG                               $47     !5, 3
        121        SEND_FUNC_ARG                                            $47
        122        DO_FCALL                                      0  $48     
        123        ASSIGN                                                   !6, $48
        124      > JMP                                                      ->221
   21   125    >   INIT_FCALL_BY_NAME                                       'bcdiv'
        126        CHECK_FUNC_ARG                                           
        127        FETCH_DIM_FUNC_ARG                               $50     !5, 1
        128        SEND_FUNC_ARG                                            $50
        129        CHECK_FUNC_ARG                                           
        130        FETCH_DIM_FUNC_ARG                               $51     !5, 3
        131        SEND_FUNC_ARG                                            $51
        132        DO_FCALL                                      0  $52     
        133        ASSIGN                                                   !6, $52
        134      > JMP                                                      ->221
   22   135    >   INIT_FCALL_BY_NAME                                       'bcmod'
        136        CHECK_FUNC_ARG                                           
        137        FETCH_DIM_FUNC_ARG                               $54     !5, 1
        138        SEND_FUNC_ARG                                            $54
        139        CHECK_FUNC_ARG                                           
        140        FETCH_DIM_FUNC_ARG                               $55     !5, 3
        141        SEND_FUNC_ARG                                            $55
        142        DO_FCALL                                      0  $56     
        143        ASSIGN                                                   !6, $56
        144      > JMP                                                      ->221
   23   145    >   INIT_FCALL_BY_NAME                                       'bcpow'
        146        CHECK_FUNC_ARG                                           
        147        FETCH_DIM_FUNC_ARG                               $58     !5, 1
        148        SEND_FUNC_ARG                                            $58
        149        CHECK_FUNC_ARG                                           
        150        FETCH_DIM_FUNC_ARG                               $59     !5, 3
        151        SEND_FUNC_ARG                                            $59
        152        DO_FCALL                                      0  $60     
        153        ASSIGN                                                   !6, $60
        154      > JMP                                                      ->221
   25   155    >   INIT_FCALL_BY_NAME                                       'bccomp'
        156        CHECK_FUNC_ARG                                           
        157        FETCH_DIM_FUNC_ARG                               $62     !5, 1
        158        SEND_FUNC_ARG                                            $62
        159        CHECK_FUNC_ARG                                           
        160        FETCH_DIM_FUNC_ARG                               $63     !5, 3
        161        SEND_FUNC_ARG                                            $63
        162        DO_FCALL                                      0  $64     
        163        IS_EQUAL                                         ~65     $64, 0
        164        ASSIGN                                                   !6, ~65
        165      > JMP                                                      ->221
   26   166    >   INIT_FCALL_BY_NAME                                       'bccomp'
        167        CHECK_FUNC_ARG                                           
        168        FETCH_DIM_FUNC_ARG                               $67     !5, 1
        169        SEND_FUNC_ARG                                            $67
        170        CHECK_FUNC_ARG                                           
        171        FETCH_DIM_FUNC_ARG                               $68     !5, 3
        172        SEND_FUNC_ARG                                            $68
        173        DO_FCALL                                      0  $69     
        174        IS_EQUAL                                         ~70     $69, 1
        175        ASSIGN                                                   !6, ~70
        176      > JMP                                                      ->221
   27   177    >   INIT_FCALL_BY_NAME                                       'bccomp'
        178        CHECK_FUNC_ARG                                           
        179        FETCH_DIM_FUNC_ARG                               $72     !5, 1
        180        SEND_FUNC_ARG                                            $72
        181        CHECK_FUNC_ARG                                           
        182        FETCH_DIM_FUNC_ARG                               $73     !5, 3
        183        SEND_FUNC_ARG                                            $73
        184        DO_FCALL                                      0  $74     
        185        IS_EQUAL                                         ~75     $74, -1
        186        ASSIGN                                                   !6, ~75
        187      > JMP                                                      ->221
   28   188    >   INIT_FCALL_BY_NAME                                       'bccomp'
        189        CHECK_FUNC_ARG                                           
        190        FETCH_DIM_FUNC_ARG                               $77     !5, 1
        191        SEND_FUNC_ARG                                            $77
        192        CHECK_FUNC_ARG                                           
        193        FETCH_DIM_FUNC_ARG                               $78     !5, 3
        194        SEND_FUNC_ARG                                            $78
        195        DO_FCALL                                      0  $79     
        196        IS_SMALLER_OR_EQUAL                              ~80     0, $79
        197        ASSIGN                                                   !6, ~80
        198      > JMP                                                      ->221
   29   199    >   INIT_FCALL_BY_NAME                                       'bccomp'
        200        CHECK_FUNC_ARG                                           
        201        FETCH_DIM_FUNC_ARG                               $82     !5, 1
        202        SEND_FUNC_ARG                                            $82
        203        CHECK_FUNC_ARG                                           
        204        FETCH_DIM_FUNC_ARG                               $83     !5, 3
        205        SEND_FUNC_ARG                                            $83
        206        DO_FCALL                                      0  $84     
        207        IS_SMALLER_OR_EQUAL                              ~85     $84, 0
        208        ASSIGN                                                   !6, ~85
        209      > JMP                                                      ->221
   31   210    >   INIT_FCALL_BY_NAME                                       'bccomp'
        211        CHECK_FUNC_ARG                                           
        212        FETCH_DIM_FUNC_ARG                               $87     !5, 1
        213        SEND_FUNC_ARG                                            $87
        214        CHECK_FUNC_ARG                                           
        215        FETCH_DIM_FUNC_ARG                               $88     !5, 3
        216        SEND_FUNC_ARG                                            $88
        217        DO_FCALL                                      0  $89     
        218        IS_NOT_EQUAL                                     ~90     $89, 0
        219        ASSIGN                                                   !6, ~90
        220      > JMP                                                      ->221
        221    >   FREE                                                     ~36
   33   222        INIT_FCALL                                               'str_replace'
        223        FETCH_DIM_R                                      ~93     !5, 0
        224        SEND_VAL                                                 ~93
        225        SEND_VAR                                                 !6
        226        FETCH_DIM_R                                      ~94     !4, 1
        227        SEND_VAL                                                 ~94
        228        DO_ICALL                                         $95     
        229        ASSIGN_DIM                                               !4, 1
        230        OP_DATA                                                  $95
   15   231    > > JMP                                                      ->53
        232    >   FE_FREE                                                  $30
   36   233        INIT_FCALL                                               'str_replace'
        234        FETCH_DIM_R                                      ~96     !4, 0
        235        SEND_VAL                                                 ~96
        236        FETCH_DIM_R                                      ~97     !4, 1
        237        SEND_VAL                                                 ~97
        238        SEND_VAR                                                 !1
        239        DO_ICALL                                         $98     
        240        ASSIGN                                                   !1, $98
   14   241    >   INIT_FCALL                                               'preg_match'
        242        SEND_VAL                                                 '%2F%5C%28%28%5B%5E%5C%29%5C%28%5D%2A%29%5C%29%2F'
        243        SEND_VAR                                                 !1
        244        SEND_REF                                                 !4
        245        DO_ICALL                                         $100    
        246      > JMPNZ                                                    $100, ->52
   39   247    > > RETURN                                                   !1
   40   248*     > RETURN                                                   null

End of function bc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.32 ms | 1047 KiB | 19 Q