3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calculate_string( $mathString ) { $mathString = trim($mathString); // trim white spaces $mathString = preg_replace('#[^0-9\+-\*\/\(\) ]#', '', $mathString); // remove any non-numbers chars; exception for math operators var_dump($mathString); $compute = create_function("", "return (" . $mathString . ");" ); return 0 + $compute(); } $string = " (1 + 1) * (2 + 2)"; echo calculate_string($string); // outputs 8
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NiJgY
function name:  (null)
number of ops:  6
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, '+%281+%2B+1%29+%2A+%282+%2B+2%29'
   11     1        INIT_FCALL                                               'calculate_string'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function calculate_string:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NiJgY
function name:  calculate_string
number of ops:  26
compiled vars:  !0 = $mathString, !1 = $compute
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
    4     5        INIT_FCALL                                               'preg_replace'
          6        SEND_VAL                                                 '%23%5B%5E0-9%5C%2B-%5C%2A%5C%2F%5C%28%5C%29+%5D%23'
          7        SEND_VAL                                                 ''
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $4      
         10        ASSIGN                                                   !0, $4
    5    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
    6    14        INIT_FCALL_BY_NAME                                       'create_function'
         15        SEND_VAL_EX                                              ''
         16        CONCAT                                           ~7      'return+%28', !0
         17        CONCAT                                           ~8      ~7, '%29%3B'
         18        SEND_VAL_EX                                              ~8
         19        DO_FCALL                                      0  $9      
         20        ASSIGN                                                   !1, $9
    7    21        INIT_DYNAMIC_CALL                                        !1
         22        DO_FCALL                                      0  $11     
         23        ADD                                              ~12     0, $11
         24      > RETURN                                                   ~12
    8    25*     > RETURN                                                   null

End of function calculate_string

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.93 ms | 1399 KiB | 20 Q