3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SlightlyLessBollocksMySQLi extends mysqli { public function prepareWithParams($query, $params) { $tokens = $this->getQueryTokens($query); $query = ''; $args = ['']; $paramRefs = []; $i = 1; foreach ($tokens as $token) { if ($token !== '?') { $query .= $token; continue; } $paramRefs[$i] = array_shift($params); switch (true) { case is_array($paramRefs[$i]): $query .= implode(', ', array_fill(0, count($paramRefs[$i]), '?')); array_splice($paramRefs, $i, 1, $paramRefs[$i]); for ($j = $i; isset($paramRefs[$j]); $j++) { switch (true) { case is_int($paramRefs[$j]): case is_bool($paramRefs[$j]): $args[0] .= 'i'; $paramRefs[$j] = (int)$paramRefs[$j]; break; case is_float($paramRefs[$j]): $args[0] .= 'd'; break; default: $args[0] .= 's'; $paramRefs[$j] = (string)$paramRefs[$j]; break; } $args[] = &$paramRefs[$j]; } $i = $j; break; case is_int($paramRefs[$i]): case is_bool($paramRefs[$i]): $args[0] .= 'i'; $query .= '?'; $paramRefs[$i] = (int)$paramRefs[$i]; $args[] = &$paramRefs[$i++]; break; case is_float($paramRefs[$i]): $args[0] .= 'd'; $query .= '?'; $args[] = &$paramRefs[$i++]; break; default: $args[0] .= 's'; $query .= '?'; $paramRefs[$i] = (string)$paramRefs[$i]; $args[] = &$paramRefs[$i++]; break; } } $stmt = $this->prepare($query); call_user_func_array([$stmt, 'bind_param'], $args); return $stmt; } /** * @param string $token * @return bool */ private function isQuotedString($token) { return in_array($token[0], array('"', "'")) && $token[0] == $token[strlen($token) - 1]; } /** * "Tokenize" the query * * Actually all this does is split the query up into things that are and are not quoted strings, to avoid treating * a literal question mark as a placeholder. * * @param string $query * @return string[] */ private function getQueryTokens($query) { static $expr = '/("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/'; $tokens = []; foreach (preg_split($expr, $query, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $token) { if ($this->isQuotedString($token)) { $tokens[] = $token; } else { $tokens = array_merge($tokens, preg_split('/(\?)/', $token, -1, PREG_SPLIT_DELIM_CAPTURE)); } } return $tokens; } } (new SlightlyLessBollocksMySQLi)->prepareWithParams("SELECT * FROM foo WHERE 'a' = b AND foo = ? AND bar IN(?)", [2, [1, 2, 12.345, "hello", true]]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ5br
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'slightlylessbollocksmysqli', 'mysqli'
  113     1        NEW                                              $0      'SlightlyLessBollocksMySQLi'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $0, 'prepareWithParams'
          4        SEND_VAL_EX                                              'SELECT+%2A+FROM+foo+WHERE+%27a%27+%3D+b+AND+foo+%3D+%3F+AND+bar+IN%28%3F%29'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class SlightlyLessBollocksMySQLi:
Function preparewithparams:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 127
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 127
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 34
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 91
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 91
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 104
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
Branch analysis from position: 91
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 89, Position 2 = 55
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 65
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 65
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 72
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 89, Position 2 = 55
Branch analysis from position: 89
Branch analysis from position: 55
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 65
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 127
filename:       /in/AQ5br
function name:  prepareWithParams
number of ops:  140
compiled vars:  !0 = $query, !1 = $params, !2 = $tokens, !3 = $args, !4 = $paramRefs, !5 = $i, !6 = $token, !7 = $j, !8 = $stmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_METHOD_CALL                                         'getQueryTokens'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $9      
          5        ASSIGN                                                   !2, $9
    8     6        ASSIGN                                                   !0, ''
    9     7        ASSIGN                                                   !3, <array>
   10     8        ASSIGN                                                   !4, <array>
   11     9        ASSIGN                                                   !5, 1
   13    10      > FE_RESET_R                                       $15     !2, ->127
         11    > > FE_FETCH_R                                               $15, !6, ->127
   14    12    >   IS_NOT_IDENTICAL                                         !6, '%3F'
         13      > JMPZ                                                     ~16, ->16
   15    14    >   ASSIGN_OP                                     8          !0, !6
   16    15      > JMP                                                      ->11
   19    16    >   INIT_FCALL                                               'array_shift'
         17        SEND_REF                                                 !1
         18        DO_ICALL                                         $19     
         19        ASSIGN_DIM                                               !4, !5
         20        OP_DATA                                                  $19
   21    21        FETCH_DIM_R                                      ~21     !4, !5
         22        TYPE_CHECK                                  128          ~21
         23      > JMPNZ                                                    ~22, ->34
   49    24    >   FETCH_DIM_R                                      ~23     !4, !5
         25        TYPE_CHECK                                   16          ~23
         26      > JMPNZ                                                    ~24, ->91
   50    27    >   FETCH_DIM_R                                      ~25     !4, !5
         28        TYPE_CHECK                                   12          ~25
         29      > JMPNZ                                                    ~26, ->91
   57    30    >   FETCH_DIM_R                                      ~27     !4, !5
         31        TYPE_CHECK                                   32          ~27
         32      > JMPNZ                                                    ~28, ->104
         33    > > JMP                                                      ->113
   22    34    >   INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '%2C+'
         36        INIT_FCALL                                               'array_fill'
         37        SEND_VAL                                                 0
         38        FETCH_DIM_R                                      ~29     !4, !5
         39        COUNT                                            ~30     ~29
         40        SEND_VAL                                                 ~30
         41        SEND_VAL                                                 '%3F'
         42        DO_ICALL                                         $31     
         43        SEND_VAR                                                 $31
         44        DO_ICALL                                         $32     
         45        ASSIGN_OP                                     8          !0, $32
   24    46        INIT_FCALL                                               'array_splice'
         47        SEND_REF                                                 !4
         48        SEND_VAR                                                 !5
         49        SEND_VAL                                                 1
         50        FETCH_DIM_R                                      ~34     !4, !5
         51        SEND_VAL                                                 ~34
         52        DO_ICALL                                                 
   26    53        ASSIGN                                                   !7, !5
         54      > JMP                                                      ->87
   28    55    >   FETCH_DIM_R                                      ~38     !4, !7
         56        TYPE_CHECK                                   16          ~38
         57      > JMPNZ                                                    ~39, ->65
   29    58    >   FETCH_DIM_R                                      ~40     !4, !7
         59        TYPE_CHECK                                   12          ~40
         60      > JMPNZ                                                    ~41, ->65
   34    61    >   FETCH_DIM_R                                      ~42     !4, !7
         62        TYPE_CHECK                                   32          ~42
         63      > JMPNZ                                                    ~43, ->72
         64    > > JMP                                                      ->75
   30    65    >   ASSIGN_DIM_OP                .=               8          !3, 0
         66        OP_DATA                                                  'i'
   31    67        FETCH_DIM_R                                      ~46     !4, !7
         68        CAST                                          4  ~47     ~46
         69        ASSIGN_DIM                                               !4, !7
         70        OP_DATA                                                  ~47
   32    71      > JMP                                                      ->82
   35    72    >   ASSIGN_DIM_OP                .=               8          !3, 0
         73        OP_DATA                                                  'd'
   36    74      > JMP                                                      ->82
   39    75    >   ASSIGN_DIM_OP                .=               8          !3, 0
         76        OP_DATA                                                  's'
   40    77        FETCH_DIM_R                                      ~51     !4, !7
         78        CAST                                          6  ~52     ~51
         79        ASSIGN_DIM                                               !4, !7
         80        OP_DATA                                                  ~52
   41    81      > JMP                                                      ->82
   43    82    >   FETCH_DIM_W                                      $54     !4, !7
         83        MAKE_REF                                         $55     $54
         84        FETCH_DIM_W                                      $53     !3
         85        ASSIGN_REF                                               $53, $55
   26    86        PRE_INC                                                  !7
         87    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, !7
         88      > JMPNZ                                                    ~58, ->55
   46    89    >   ASSIGN                                                   !5, !7
   47    90      > JMP                                                      ->126
   51    91    >   ASSIGN_DIM_OP                .=               8          !3, 0
         92        OP_DATA                                                  'i'
   52    93        ASSIGN_OP                                     8          !0, '%3F'
   53    94        FETCH_DIM_R                                      ~63     !4, !5
         95        CAST                                          4  ~64     ~63
         96        ASSIGN_DIM                                               !4, !5
         97        OP_DATA                                                  ~64
   54    98        POST_INC                                         ~66     !5
         99        FETCH_DIM_W                                      $67     !4, ~66
        100        MAKE_REF                                         $68     $67
        101        FETCH_DIM_W                                      $65     !3
        102        ASSIGN_REF                                               $65, $68
   55   103      > JMP                                                      ->126
   58   104    >   ASSIGN_DIM_OP                .=               8          !3, 0
        105        OP_DATA                                                  'd'
   59   106        ASSIGN_OP                                     8          !0, '%3F'
   60   107        POST_INC                                         ~73     !5
        108        FETCH_DIM_W                                      $74     !4, ~73
        109        MAKE_REF                                         $75     $74
        110        FETCH_DIM_W                                      $72     !3
        111        ASSIGN_REF                                               $72, $75
   61   112      > JMP                                                      ->126
   64   113    >   ASSIGN_DIM_OP                .=               8          !3, 0
        114        OP_DATA                                                  's'
   65   115        ASSIGN_OP                                     8          !0, '%3F'
   66   116        FETCH_DIM_R                                      ~80     !4, !5
        117        CAST                                          6  ~81     ~80
        118        ASSIGN_DIM                                               !4, !5
        119        OP_DATA                                                  ~81
   67   120        POST_INC                                         ~83     !5
        121        FETCH_DIM_W                                      $84     !4, ~83
        122        MAKE_REF                                         $85     $84
        123        FETCH_DIM_W                                      $82     !3
        124        ASSIGN_REF                                               $82, $85
   68   125      > JMP                                                      ->126
   13   126    > > JMP                                                      ->11
        127    >   FE_FREE                                                  $15
   72   128        INIT_METHOD_CALL                                         'prepare'
        129        SEND_VAR_EX                                              !0
        130        DO_FCALL                                      0  $87     
        131        ASSIGN                                                   !8, $87
   73   132        INIT_ARRAY                                       ~89     !8
        133        ADD_ARRAY_ELEMENT                                ~89     'bind_param'
        134        INIT_USER_CALL                                0          'call_user_func_array', ~89
        135        SEND_ARRAY                                               !3
        136        CHECK_UNDEF_ARGS                                         
        137        DO_FCALL                                      0          
   75   138      > RETURN                                                   !8
   76   139*     > RETURN                                                   null

End of function preparewithparams

Function isquotedstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/AQ5br
function name:  isQuotedString
number of ops:  12
compiled vars:  !0 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   84     1        FETCH_DIM_R                                      ~1      !0, 0
          2        IN_ARRAY                                         ~2      ~1, <array>
          3      > JMPZ_EX                                          ~2      ~2, ->10
          4    >   FETCH_DIM_R                                      ~3      !0, 0
          5        STRLEN                                           ~4      !0
          6        SUB                                              ~5      ~4, 1
          7        FETCH_DIM_R                                      ~6      !0, ~5
          8        IS_EQUAL                                         ~7      ~3, ~6
          9        BOOL                                             ~2      ~7
         10    > > RETURN                                                   ~2
   85    11*     > RETURN                                                   null

End of function isquotedstring

Function getquerytokens:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/AQ5br
function name:  getQueryTokens
number of ops:  33
compiled vars:  !0 = $query, !1 = $expr, !2 = $tokens, !3 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   RECV                                             !0      
   98     1        BIND_STATIC                                              !1
   99     2        ASSIGN                                                   !2, <array>
  101     3        INIT_FCALL                                               'preg_split'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 -1
          7        SEND_VAL                                                 3
          8        DO_ICALL                                         $5      
          9      > FE_RESET_R                                       $6      $5, ->30
         10    > > FE_FETCH_R                                               $6, !3, ->30
  102    11    >   INIT_METHOD_CALL                                         'isQuotedString'
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $7      
         14      > JMPZ                                                     $7, ->18
  103    15    >   ASSIGN_DIM                                               !2
         16        OP_DATA                                                  !3
         17      > JMP                                                      ->29
  105    18    >   INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !2
         20        INIT_FCALL                                               'preg_split'
         21        SEND_VAL                                                 '%2F%28%5C%3F%29%2F'
         22        SEND_VAR                                                 !3
         23        SEND_VAL                                                 -1
         24        SEND_VAL                                                 2
         25        DO_ICALL                                         $9      
         26        SEND_VAR                                                 $9
         27        DO_ICALL                                         $10     
         28        ASSIGN                                                   !2, $10
  101    29    > > JMP                                                      ->10
         30    >   FE_FREE                                                  $6
  109    31      > RETURN                                                   !2
  110    32*     > RETURN                                                   null

End of function getquerytokens

End of class SlightlyLessBollocksMySQLi.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.35 ms | 1416 KiB | 25 Q