3v4l.org

run code in 300+ PHP versions simultaneously
<?php function evalJS($code) { $matches = []; preg_match_all('#var (.*)( |=|;)#', $code, $matches); foreach($matches[1] as $val) { $code = preg_replace('#'.$val.'#', '\$'.$val, $code); $code = preg_replace('#var \$'.$val.'#', '\$'.$val, $code); $code = preg_replace('#\$'.$val.'\.#', '\$'.$val.'->', $code); } $code = preg_replace('#\.#', '::', $code); $code = preg_replace('#(\'|")\+#', '$1.', $code); $code = preg_replace('#\+(\'|")#', '.$1', $code); echo($code); var_dump($matches); } class document { public function print($arg) { echo($arg); } } $js = <<<JS var foo = "Hello "+"World!"; document.print(foo); JS; evalJS($js);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtcU6
function name:  (null)
number of ops:  5
compiled vars:  !0 = $js
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 'var+foo+%3D+%22Hello+%22%2B%22World%21%22%3B%0Adocument.print%28foo%29%3B'
   30     1        INIT_FCALL                                               'evaljs'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function evaljs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 39
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 39
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/gtcU6
function name:  evalJS
number of ops:  63
compiled vars:  !0 = $code, !1 = $matches, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAL                                                 '%23var+%28.%2A%29%28+%7C%3D%7C%3B%29%23'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !1
          6        DO_ICALL                                                 
    6     7        FETCH_DIM_R                                      ~5      !1, 1
          8      > FE_RESET_R                                       $6      ~5, ->39
          9    > > FE_FETCH_R                                               $6, !2, ->39
    8    10    >   INIT_FCALL                                               'preg_replace'
         11        CONCAT                                           ~7      '%23', !2
         12        CONCAT                                           ~8      ~7, '%23'
         13        SEND_VAL                                                 ~8
         14        CONCAT                                           ~9      '%5C%24', !2
         15        SEND_VAL                                                 ~9
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $10     
         18        ASSIGN                                                   !0, $10
    9    19        INIT_FCALL                                               'preg_replace'
         20        CONCAT                                           ~12     '%23var+%5C%24', !2
         21        CONCAT                                           ~13     ~12, '%23'
         22        SEND_VAL                                                 ~13
         23        CONCAT                                           ~14     '%5C%24', !2
         24        SEND_VAL                                                 ~14
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $15     
         27        ASSIGN                                                   !0, $15
   10    28        INIT_FCALL                                               'preg_replace'
         29        CONCAT                                           ~17     '%23%5C%24', !2
         30        CONCAT                                           ~18     ~17, '%5C.%23'
         31        SEND_VAL                                                 ~18
         32        CONCAT                                           ~19     '%5C%24', !2
         33        CONCAT                                           ~20     ~19, '-%3E'
         34        SEND_VAL                                                 ~20
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $21     
         37        ASSIGN                                                   !0, $21
    6    38      > JMP                                                      ->9
         39    >   FE_FREE                                                  $6
   12    40        INIT_FCALL                                               'preg_replace'
         41        SEND_VAL                                                 '%23%5C.%23'
         42        SEND_VAL                                                 '%3A%3A'
         43        SEND_VAR                                                 !0
         44        DO_ICALL                                         $23     
         45        ASSIGN                                                   !0, $23
   13    46        INIT_FCALL                                               'preg_replace'
         47        SEND_VAL                                                 '%23%28%27%7C%22%29%5C%2B%23'
         48        SEND_VAL                                                 '%241.'
         49        SEND_VAR                                                 !0
         50        DO_ICALL                                         $25     
         51        ASSIGN                                                   !0, $25
   14    52        INIT_FCALL                                               'preg_replace'
         53        SEND_VAL                                                 '%23%5C%2B%28%27%7C%22%29%23'
         54        SEND_VAL                                                 '.%241'
         55        SEND_VAR                                                 !0
         56        DO_ICALL                                         $27     
         57        ASSIGN                                                   !0, $27
   15    58        ECHO                                                     !0
   16    59        INIT_FCALL                                               'var_dump'
         60        SEND_VAR                                                 !1
         61        DO_ICALL                                                 
   17    62      > RETURN                                                   null

End of function evaljs

Class document:
Function print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gtcU6
function name:  print
number of ops:  3
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        ECHO                                                     !0
   23     2      > RETURN                                                   null

End of function print

End of class document.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.39 ms | 1394 KiB | 20 Q