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('#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/vaXGn
function name:  (null)
number of ops:  5
compiled vars:  !0 = $js
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, 'var+foo+%3D+%22Hello+%22%2B%22World%21%22%3B%0Adocument.print%28foo%29%3B'
   29     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 = 30
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/vaXGn
function name:  evalJS
number of ops:  54
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, ->30
          9    > > FE_FETCH_R                                               $6, !2, ->30
    8    10    >   INIT_FCALL                                               'preg_replace'
         11        CONCAT                                           ~7      '%23var+', !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     '%23%5C%24', !2
         21        CONCAT                                           ~13     ~12, '%5C.%23'
         22        SEND_VAL                                                 ~13
         23        CONCAT                                           ~14     '%5C%24', !2
         24        CONCAT                                           ~15     ~14, '-%3E'
         25        SEND_VAL                                                 ~15
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !0, $16
    6    29      > JMP                                                      ->9
         30    >   FE_FREE                                                  $6
   11    31        INIT_FCALL                                               'preg_replace'
         32        SEND_VAL                                                 '%23%5C.%23'
         33        SEND_VAL                                                 '%3A%3A'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $18     
         36        ASSIGN                                                   !0, $18
   12    37        INIT_FCALL                                               'preg_replace'
         38        SEND_VAL                                                 '%23%28%27%7C%22%29%5C%2B%23'
         39        SEND_VAL                                                 '%241.'
         40        SEND_VAR                                                 !0
         41        DO_ICALL                                         $20     
         42        ASSIGN                                                   !0, $20
   13    43        INIT_FCALL                                               'preg_replace'
         44        SEND_VAL                                                 '%23%5C%2B%28%27%7C%22%29%23'
         45        SEND_VAL                                                 '.%241'
         46        SEND_VAR                                                 !0
         47        DO_ICALL                                         $22     
         48        ASSIGN                                                   !0, $22
   14    49        ECHO                                                     !0
   15    50        INIT_FCALL                                               'var_dump'
         51        SEND_VAR                                                 !1
         52        DO_ICALL                                                 
   16    53      > 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/vaXGn
function name:  print
number of ops:  3
compiled vars:  !0 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ECHO                                                     !0
   22     2      > RETURN                                                   null

End of function print

End of class document.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.71 ms | 1403 KiB | 20 Q