3v4l.org

run code in 300+ PHP versions simultaneously
<?php function expandArguments(&$query, &$args) { $modified = FALSE; foreach (array_filter($args, 'is_array') as $key => $data) { $new_keys = array(); foreach ($data as $i => $value) { $new_keys[$key . '_' . $i] = $value; } $query = preg_replace( '#' . $key . '\b#', implode(', ', array_keys($new_keys)), $query ); unset($args[$key]); $args += $new_keys; $modified = TRUE; } return $modified; } function expandArguments2(&$query, &$args) { $modified = FALSE; foreach (array_filter($args, 'is_array') as $key => $data) { $new_keys = array(); foreach (array_values($data) as $i => $value) { $new_keys[$key . '_' . $i] = $value; } $query = preg_replace( '#' . $key . '\b#', implode(', ', array_keys($new_keys)), $query ); unset($args[$key]); $args += $new_keys; $modified = TRUE; } return $modified; } $query = "SELECT * FROM foo WHERE id IN (:ids)"; $args = array( 'ids' => array( 1, 2, '0); DROP TABLE foo; --' => 3 ) ); expandArguments($query, $args); var_dump($query, $args);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/imbaC
function name:  (null)
number of ops:  11
compiled vars:  !0 = $query, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, 'SELECT+%2A+FROM+foo+WHERE+id+IN+%28%3Aids%29'
   45     1        ASSIGN                                                   !1, <array>
   52     2        INIT_FCALL                                               'expandarguments'
          3        SEND_REF                                                 !0
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0          
   54     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function expandarguments:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 39
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 39
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/imbaC
function name:  expandArguments
number of ops:  42
compiled vars:  !0 = $query, !1 = $args, !2 = $modified, !3 = $data, !4 = $key, !5 = $new_keys, !6 = $value, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <false>
    5     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 'is_array'
          6        DO_ICALL                                         $9      
          7      > FE_RESET_R                                       $10     $9, ->39
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->39
          9    >   ASSIGN                                                   !4, ~11
    6    10        ASSIGN                                                   !5, <array>
    7    11      > FE_RESET_R                                       $14     !3, ->19
         12    > > FE_FETCH_R                                       ~15     $14, !6, ->19
         13    >   ASSIGN                                                   !7, ~15
    8    14        CONCAT                                           ~17     !4, '_'
         15        CONCAT                                           ~18     ~17, !7
         16        ASSIGN_DIM                                               !5, ~18
         17        OP_DATA                                                  !6
    7    18      > JMP                                                      ->12
         19    >   FE_FREE                                                  $14
   10    20        INIT_FCALL                                               'preg_replace'
   11    21        CONCAT                                           ~20     '%23', !4
         22        CONCAT                                           ~21     ~20, '%5Cb%23'
         23        SEND_VAL                                                 ~21
   12    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '%2C+'
         26        INIT_FCALL                                               'array_keys'
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $22     
         29        SEND_VAR                                                 $22
         30        DO_ICALL                                         $23     
         31        SEND_VAR                                                 $23
   13    32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $24     
   10    34        ASSIGN                                                   !0, $24
   15    35        UNSET_DIM                                                !1, !4
   16    36        ASSIGN_OP                                     1          !1, !5
   17    37        ASSIGN                                                   !2, <true>
    5    38      > JMP                                                      ->8
         39    >   FE_FREE                                                  $10
   19    40      > RETURN                                                   !2
   20    41*     > RETURN                                                   null

End of function expandarguments

Function expandarguments2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 42
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 42
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/imbaC
function name:  expandArguments2
number of ops:  45
compiled vars:  !0 = $query, !1 = $args, !2 = $modified, !3 = $data, !4 = $key, !5 = $new_keys, !6 = $value, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        ASSIGN                                                   !2, <false>
   25     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 'is_array'
          6        DO_ICALL                                         $9      
          7      > FE_RESET_R                                       $10     $9, ->42
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->42
          9    >   ASSIGN                                                   !4, ~11
   26    10        ASSIGN                                                   !5, <array>
   27    11        INIT_FCALL                                               'array_values'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $14     
         14      > FE_RESET_R                                       $15     $14, ->22
         15    > > FE_FETCH_R                                       ~16     $15, !6, ->22
         16    >   ASSIGN                                                   !7, ~16
   28    17        CONCAT                                           ~18     !4, '_'
         18        CONCAT                                           ~19     ~18, !7
         19        ASSIGN_DIM                                               !5, ~19
         20        OP_DATA                                                  !6
   27    21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $15
   30    23        INIT_FCALL                                               'preg_replace'
   31    24        CONCAT                                           ~21     '%23', !4
         25        CONCAT                                           ~22     ~21, '%5Cb%23'
         26        SEND_VAL                                                 ~22
   32    27        INIT_FCALL                                               'implode'
         28        SEND_VAL                                                 '%2C+'
         29        INIT_FCALL                                               'array_keys'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                         $23     
         32        SEND_VAR                                                 $23
         33        DO_ICALL                                         $24     
         34        SEND_VAR                                                 $24
   33    35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $25     
   30    37        ASSIGN                                                   !0, $25
   35    38        UNSET_DIM                                                !1, !4
   36    39        ASSIGN_OP                                     1          !1, !5
   37    40        ASSIGN                                                   !2, <true>
   25    41      > JMP                                                      ->8
         42    >   FE_FREE                                                  $10
   39    43      > RETURN                                                   !2
   40    44*     > RETURN                                                   null

End of function expandarguments2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.91 ms | 1406 KiB | 26 Q