3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = '2+3*pi'; // Remove whitespaces $test = preg_replace('/\s+/', '', $test); $number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number $functions = '(?:sinh?|cosh?|tanh?|abs|acosh?|asinh?|atanh?|exp|log10|deg2rad|rad2deg|sqrt|ceil|floor|round)'; // Allowed PHP functions $operators = '[+\/*\^%-]'; // Allowed math operators $regexp = '/^(('.$number.'|'.$functions.'\s*\((?1)+\)|\((?1)+\))(?:'.$operators.'(?2))?)+$/'; // Final regexp, heavily using recursive patterns if (preg_match($regexp, $q)) { $test = preg_replace('!pi|π!', 'pi()', $test); // Replace pi with pi function eval('$result = '.$test.';'); } else { $result = false; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 32
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hmWEd
function name:  (null)
number of ops:  34
compiled vars:  !0 = $test, !1 = $number, !2 = $functions, !3 = $operators, !4 = $regexp, !5 = $q, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '2%2B3%2Api'
    5     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5Cs%2B%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !0, $8
    7     7        ASSIGN                                                   !1, '%28%3F%3A%5Cd%2B%28%3F%3A%5B%2C.%5D%5Cd%2B%29%3F%7Cpi%7C%CF%80%29'
    8     8        ASSIGN                                                   !2, '%28%3F%3Asinh%3F%7Ccosh%3F%7Ctanh%3F%7Cabs%7Cacosh%3F%7Casinh%3F%7Catanh%3F%7Cexp%7Clog10%7Cdeg2rad%7Crad2deg%7Csqrt%7Cceil%7Cfloor%7Cround%29'
    9     9        ASSIGN                                                   !3, '%5B%2B%5C%2F%2A%5C%5E%25-%5D'
   10    10        CONCAT                                           ~13     '%2F%5E%28%28', !1
         11        CONCAT                                           ~14     ~13, '%7C'
         12        CONCAT                                           ~15     ~14, !2
         13        CONCAT                                           ~16     ~15, '%5Cs%2A%5C%28%28%3F1%29%2B%5C%29%7C%5C%28%28%3F1%29%2B%5C%29%29%28%3F%3A'
         14        CONCAT                                           ~17     ~16, !3
         15        CONCAT                                           ~18     ~17, '%28%3F2%29%29%3F%29%2B%24%2F'
         16        ASSIGN                                                   !4, ~18
   12    17        INIT_FCALL                                               'preg_match'
         18        SEND_VAR                                                 !4
         19        SEND_VAR                                                 !5
         20        DO_ICALL                                         $20     
         21      > JMPZ                                                     $20, ->32
   14    22    >   INIT_FCALL                                               'preg_replace'
         23        SEND_VAL                                                 '%21pi%7C%CF%80%21'
         24        SEND_VAL                                                 'pi%28%29'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $21     
         27        ASSIGN                                                   !0, $21
   15    28        CONCAT                                           ~23     '%24result+%3D+', !0
         29        CONCAT                                           ~24     ~23, '%3B'
         30        INCLUDE_OR_EVAL                                          ~24, EVAL
         31      > JMP                                                      ->33
   19    32    >   ASSIGN                                                   !6, <false>
   20    33    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.3 ms | 1396 KiB | 17 Q