3v4l.org

run code in 300+ PHP versions simultaneously
<?php function escape(string $query) { return preg_replace_callback('/{(([^.}]+?)\.)?(.*?)}/', function ($matches) { $quoted = ''; // Quote table name. If there is an explicit database, quote it, too. if ($matches[2] !== '') { $quoted .= '`' . $matches[2] . '`.'; } // Quote the table name, keeping curly brackets so potential prefixes can // be added later. $quoted .= '`{' . $matches[3] . '}`'; return $quoted; }, $query); } var_dump(escape('SELECT * FROM system')); var_dump(escape('SELECT * FROM {system} ')); var_dump(escape('SELECT * FROM {db.system}')); var_dump(escape('SELECT * FROM db.system'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YtN8T
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'escape'
          2        SEND_VAL                                                 'SELECT+%2A+FROM+system'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   20     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'escape'
          8        SEND_VAL                                                 'SELECT+%2A+FROM+%7Bsystem%7D+'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   21    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'escape'
         14        SEND_VAL                                                 'SELECT+%2A+FROM+%7Bdb.system%7D'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   22    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'escape'
         20        SEND_VAL                                                 'SELECT+%2A+FROM+db.system'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Function escape:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YtN8T
function name:  escape
number of ops:  9
compiled vars:  !0 = $query
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%2F%7B%28%28%5B%5E.%7D%5D%2B%3F%29%5C.%29%3F%28.%2A%3F%29%7D%2F'
          3        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
   16     4        SEND_VAL                                                 ~1
          5        SEND_VAR                                                 !0
    3     6        DO_ICALL                                         $2      
   16     7      > RETURN                                                   $2
   17     8*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/YtN8T
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $matches, !1 = $quoted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    7     2        FETCH_DIM_R                                      ~3      !0, 2
          3        IS_NOT_IDENTICAL                                         ~3, ''
          4      > JMPZ                                                     ~4, ->9
    8     5    >   FETCH_DIM_R                                      ~5      !0, 2
          6        CONCAT                                           ~6      '%60', ~5
          7        CONCAT                                           ~7      ~6, '%60.'
          8        ASSIGN_OP                                     8          !1, ~7
   13     9    >   FETCH_DIM_R                                      ~9      !0, 3
         10        CONCAT                                           ~10     '%60%7B', ~9
         11        CONCAT                                           ~11     ~10, '%7D%60'
         12        ASSIGN_OP                                     8          !1, ~11
   15    13      > RETURN                                                   !1
   16    14*     > RETURN                                                   null

End of Dynamic Function 0

End of function escape

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.76 ms | 1010 KiB | 19 Q