3v4l.org

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

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


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

End of Dynamic Function 0

End of function substitute_params

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.84 ms | 1022 KiB | 19 Q