3v4l.org

run code in 500+ PHP versions simultaneously
<?php $query = 'UPDATE `list?` set `item`=?,`type`=? WHERE ( "ty?pe?"<> \'Are yo?\' `id` = ?);'; $params = array( 'item' => '1', 'type' => 'Are you o\'k?', 'id' => '2' ); function substitute_params($query, $params) { $prep_params = str_replace(array("'","?"),array("''","\\?"),$params); $query = array_reduce($prep_params, function ($interm, $param) { return preg_replace('/^([^"\'`]*?(?:(?:`[^`]*?`[^"\'`]*?)*?(?:"[^"]*?"[^"\'`]*?)*?(?:\'[^\']*?\'[^\'"`]*?)*?)*?)(?<!\\\\)\\?/m', '${1}'.(is_numeric($param) ? $param : '\'' . $param . '\''), $interm, 1); }, $query); return "-- Not to be used as a query to database. For demonstration purposes only!\n" .str_replace("\\?", "?", $query); } echo substitute_params($query, $params); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nmQE5
function name:  (null)
number of ops:  8
compiled vars:  !0 = $query, !1 = $params
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, 'UPDATE+%60list%3F%60+set+%60item%60%3D%3F%2C%60type%60%3D%3F+%0AWHERE++%28+%22ty%3Fpe%3F%22%3C%3E+%27Are+yo%3F%27++%60id%60+%3D+%3F%29%3B'
    4     1        ASSIGN                                                       !1, <array>
   21     2        INIT_FCALL                                                   'substitute_params'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $4      
          6        ECHO                                                         $4
   22     7      > RETURN                                                       1

Function substitute_params:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nmQE5
function name:  substitute_params
number of ops:  17
compiled vars:  !0 = $query, !1 = $params, !2 = $prep_params
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        FRAMELESS_ICALL_3                str_replace         ~3      <array>, <array>
          3        OP_DATA                                                      !1
          4        ASSIGN                                                       !2, ~3
   12     5        INIT_FCALL                                                   'array_reduce'
          6        SEND_VAR                                                     !2
          7        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
   17     8        SEND_VAL                                                     ~5
          9        SEND_VAR                                                     !0
   12    10        DO_ICALL                                             $6      
         11        ASSIGN                                                       !0, $6
   19    12        FRAMELESS_ICALL_3                str_replace         ~8      '%5C%3F', '%3F'
         13        OP_DATA                                                      !0
         14        CONCAT                                               ~9      '--+Not+to+be+used+as+a+query+to+database.+For+demonstration+purposes+only%21%0A', ~8
         15      > RETURN                                                       ~9
   20    16*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nmQE5
function name:  {closure:substitute_params():12}
number of ops:  18
compiled vars:  !0 = $interm, !1 = $param
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   13     2        INIT_FCALL                                                   'preg_replace'
          3        SEND_VAL                                                     '%2F%5E%28%5B%5E%22%27%60%5D%2A%3F%28%3F%3A%28%3F%3A%60%5B%5E%60%5D%2A%3F%60%5B%5E%22%27%60%5D%2A%3F%29%2A%3F%28%3F%3A%22%5B%5E%22%5D%2A%3F%22%5B%5E%22%27%60%5D%2A%3F%29%2A%3F%28%3F%3A%27%5B%5E%27%5D%2A%3F%27%5B%5E%27%22%60%5D%2A%3F%29%2A%3F%29%2A%3F%29%28%3F%3C%21%5C%5C%29%5C%3F%2Fm'
   14     4        FRAMELESS_ICALL_1                is_numeric          ~2      !1
          5      > JMPZ                                                         ~2, ->8
          6    >   QM_ASSIGN                                            ~3      !1
          7      > JMP                                                          ->11
          8    >   CONCAT                                               ~4      '%27', !1
          9        CONCAT                                               ~5      ~4, '%27'
         10        QM_ASSIGN                                            ~3      ~5
         11    >   CONCAT                                               ~6      '%24%7B1%7D', ~3
         12        SEND_VAL                                                     ~6
   15    13        SEND_VAR                                                     !0
   16    14        SEND_VAL                                                     1
   13    15        DO_ICALL                                             $7      
   16    16      > RETURN                                                       $7
   17    17*     > RETURN                                                       null

End of Dynamic Function 0

End of function substitute_params

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.41 ms | 1745 KiB | 16 Q