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(); var_dump($data); 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(); var_dump($data); 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); $query = "SELECT * FROM foo WHERE id IN (:ids)"; $args = array( 'ids' => array( 1, 2, '0); DROP TABLE foo; --' => 3 ) ); expandArguments2($query, $args); var_dump($query, $args);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qN22D
function name:  (null)
number of ops:  21
compiled vars:  !0 = $query, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ASSIGN                                                   !0, 'SELECT+%2A+FROM+foo+WHERE+id+IN+%28%3Aids%29'
   48     1        ASSIGN                                                   !1, <array>
   55     2        INIT_FCALL                                               'expandarguments'
          3        SEND_REF                                                 !0
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0          
   57     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   59    10        ASSIGN                                                   !0, 'SELECT+%2A+FROM+foo+WHERE+id+IN+%28%3Aids%29'
   60    11        ASSIGN                                                   !1, <array>
   66    12        INIT_FCALL                                               'expandarguments2'
         13        SEND_REF                                                 !0
         14        SEND_REF                                                 !1
         15        DO_FCALL                                      0          
   67    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function expandarguments:
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/qN22D
function name:  expandArguments
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
-------------------------------------------------------------------------------------
    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, ->42
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->42
          9    >   ASSIGN                                                   !4, ~11
    6    10        ASSIGN                                                   !5, <array>
    7    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                                 
    8    14      > FE_RESET_R                                       $15     !3, ->22
         15    > > FE_FETCH_R                                       ~16     $15, !6, ->22
         16    >   ASSIGN                                                   !7, ~16
    9    17        CONCAT                                           ~18     !4, '_'
         18        CONCAT                                           ~19     ~18, !7
         19        ASSIGN_DIM                                               !5, ~19
         20        OP_DATA                                                  !6
    8    21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $15
   11    23        INIT_FCALL                                               'preg_replace'
   12    24        CONCAT                                           ~21     '%23', !4
         25        CONCAT                                           ~22     ~21, '%5Cb%23'
         26        SEND_VAL                                                 ~22
   13    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
   14    35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $25     
   11    37        ASSIGN                                                   !0, $25
   16    38        UNSET_DIM                                                !1, !4
   17    39        ASSIGN_OP                                     1          !1, !5
   18    40        ASSIGN                                                   !2, <true>
    5    41      > JMP                                                      ->8
         42    >   FE_FREE                                                  $10
   20    43      > RETURN                                                   !2
   21    44*     > 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 = 45
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 45
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/qN22D
function name:  expandArguments2
number of ops:  48
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
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        ASSIGN                                                   !2, <false>
   26     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 'is_array'
          6        DO_ICALL                                         $9      
          7      > FE_RESET_R                                       $10     $9, ->45
          8    > > FE_FETCH_R                                       ~11     $10, !3, ->45
          9    >   ASSIGN                                                   !4, ~11
   27    10        ASSIGN                                                   !5, <array>
   28    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                                 
   30    14        INIT_FCALL                                               'array_values'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $15     
         17      > FE_RESET_R                                       $16     $15, ->25
         18    > > FE_FETCH_R                                       ~17     $16, !6, ->25
         19    >   ASSIGN                                                   !7, ~17
   31    20        CONCAT                                           ~19     !4, '_'
         21        CONCAT                                           ~20     ~19, !7
         22        ASSIGN_DIM                                               !5, ~20
         23        OP_DATA                                                  !6
   30    24      > JMP                                                      ->18
         25    >   FE_FREE                                                  $16
   33    26        INIT_FCALL                                               'preg_replace'
   34    27        CONCAT                                           ~22     '%23', !4
         28        CONCAT                                           ~23     ~22, '%5Cb%23'
         29        SEND_VAL                                                 ~23
   35    30        INIT_FCALL                                               'implode'
         31        SEND_VAL                                                 '%2C+'
         32        INIT_FCALL                                               'array_keys'
         33        SEND_VAR                                                 !5
         34        DO_ICALL                                         $24     
         35        SEND_VAR                                                 $24
         36        DO_ICALL                                         $25     
         37        SEND_VAR                                                 $25
   36    38        SEND_VAR                                                 !0
         39        DO_ICALL                                         $26     
   33    40        ASSIGN                                                   !0, $26
   38    41        UNSET_DIM                                                !1, !4
   39    42        ASSIGN_OP                                     1          !1, !5
   40    43        ASSIGN                                                   !2, <true>
   26    44      > JMP                                                      ->8
         45    >   FE_FREE                                                  $10
   42    46      > RETURN                                                   !2
   43    47*     > RETURN                                                   null

End of function expandarguments2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.16 ms | 1407 KiB | 27 Q