3v4l.org

run code in 300+ PHP versions simultaneously
<?php function evalJS($code) { $matches = []; $matches = preg_match_all('#var (.*)( |=|;)#', '\$', $code); 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); eval($code); } 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/XXlYK
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+%27Hello+%27%2B%27World%21%27%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 = 10, Position 2 = 40
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 40
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/XXlYK
function name:  evalJS
number of ops:  62
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_VAL                                                 '%5C%24'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
    6     8        FETCH_DIM_R                                      ~6      !1, 1
          9      > FE_RESET_R                                       $7      ~6, ->40
         10    > > FE_FETCH_R                                               $7, !2, ->40
    8    11    >   INIT_FCALL                                               'preg_replace'
         12        CONCAT                                           ~8      '%23', !2
         13        CONCAT                                           ~9      ~8, '%23'
         14        SEND_VAL                                                 ~9
         15        CONCAT                                           ~10     '%5C%24', !2
         16        SEND_VAL                                                 ~10
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $11     
         19        ASSIGN                                                   !0, $11
    9    20        INIT_FCALL                                               'preg_replace'
         21        CONCAT                                           ~13     '%23var+%5C%24', !2
         22        CONCAT                                           ~14     ~13, '%23'
         23        SEND_VAL                                                 ~14
         24        CONCAT                                           ~15     '%5C%24', !2
         25        SEND_VAL                                                 ~15
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !0, $16
   10    29        INIT_FCALL                                               'preg_replace'
         30        CONCAT                                           ~18     '%23%5C%24', !2
         31        CONCAT                                           ~19     ~18, '%5C.%23'
         32        SEND_VAL                                                 ~19
         33        CONCAT                                           ~20     '%5C%24', !2
         34        CONCAT                                           ~21     ~20, '-%3E'
         35        SEND_VAL                                                 ~21
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $22     
         38        ASSIGN                                                   !0, $22
    6    39      > JMP                                                      ->10
         40    >   FE_FREE                                                  $7
   12    41        INIT_FCALL                                               'preg_replace'
         42        SEND_VAL                                                 '%23.%23'
         43        SEND_VAL                                                 '%3A%3A'
         44        SEND_VAR                                                 !0
         45        DO_ICALL                                         $24     
         46        ASSIGN                                                   !0, $24
   13    47        INIT_FCALL                                               'preg_replace'
         48        SEND_VAL                                                 '%23%28%27%7C%22%29%5C%2B%23'
         49        SEND_VAL                                                 '%241.'
         50        SEND_VAR                                                 !0
         51        DO_ICALL                                         $26     
         52        ASSIGN                                                   !0, $26
   14    53        INIT_FCALL                                               'preg_replace'
         54        SEND_VAL                                                 '%23%5C%2B%28%27%7C%22%29%23'
         55        SEND_VAL                                                 '.%241'
         56        SEND_VAR                                                 !0
         57        DO_ICALL                                         $28     
         58        ASSIGN                                                   !0, $28
   15    59        ECHO                                                     !0
   16    60        INCLUDE_OR_EVAL                                          !0, EVAL
   17    61      > 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/XXlYK
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:
186.85 ms | 1403 KiB | 18 Q