3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isQuotedString($token) { return in_array($token[0], array('"', "'")) && $token[0] == $token[strlen($token) - 1]; } function getQueryTokens($query) { static $expr = '/("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/'; $tokens = []; foreach (preg_split($expr, $query, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) as $token) { if (isQuotedString($token)) { $tokens[] = $token; } else { $tokens = array_merge($tokens, preg_split('/(\?)/', $token, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)); } } return $tokens; } var_dump(getQueryTokens("SELECT * FROM foo WHERE 'a' = b AND f = ? AND q IN (?)"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ibaWC
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'getquerytokens'
          2        SEND_VAL                                                 'SELECT+%2A+FROM+foo+WHERE+%27a%27+%3D+b+AND+f+%3D+%3F+AND+q+IN+%28%3F%29'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

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/ibaWC
function name:  isQuotedString
number of ops:  12
compiled vars:  !0 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     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
    6    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/ibaWC
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
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        BIND_STATIC                                              !1
   11     2        ASSIGN                                                   !2, <array>
   13     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
   14    11    >   INIT_FCALL                                               'isquotedstring'
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $7      
         14      > JMPZ                                                     $7, ->18
   15    15    >   ASSIGN_DIM                                               !2
         16        OP_DATA                                                  !3
         17      > JMP                                                      ->29
   17    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                                                 3
         25        DO_ICALL                                         $9      
         26        SEND_VAR                                                 $9
         27        DO_ICALL                                         $10     
         28        ASSIGN                                                   !2, $10
   13    29    > > JMP                                                      ->10
         30    >   FE_FREE                                                  $6
   21    31      > RETURN                                                   !2
   22    32*     > RETURN                                                   null

End of function getquerytokens

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.94 ms | 1403 KiB | 21 Q