3v4l.org

run code in 300+ PHP versions simultaneously
<?php function FormatSql($query, array $params = []) { $patt = '~ ([\'"`]) # capture this quote character (?:\\\\.|(?!\1).)* # any escaped character, or # any character that isn\'t the captured one \1 # the captured quote again (*SKIP)(*FAIL) # ignore this | \?\?? # one or two question marks | ::?\w+ # word characters marked with one or two colons~x'; return preg_replace_callback($patt, function ($matches) use (&$params) { if(!isset($matches[1])) return $matches[0]; switch($matches[1]) { case '?': if(!$params) throw new \DomainException("Not enough params"); return '*snip*'; case '??': if(!$params) throw new \DomainException("Not enough params"); return '*snip*'; case ':': if(!array_key_exists($matches[2], $params)) throw new \DomainException("\"$matches[2]\" param not provided"); return '*snip*'; case '::': if(!array_key_exists($matches[2], $params)) throw new \DomainException("\"$matches[2]\" param not provided"); return '*snip*'; } throw new \Exception("Bad regex"); }, $query); } $bigStr = str_repeat('x', 443000); $bigQuery = "INSERT INTO `emr_doc_file` (`emr_doc_id`, `edf_file`, `edf_mimetype`, `edf_upload_date`) VALUES ('108', x'$bigStr', 'application/pdf', 1490978009)"; $result = FormatSql($bigQuery, []); if($result === null) { throw new \Exception("preg error: " . preg_last_error() . "\nsee: http://php.net/manual/en/pcre.constants.php#117743"); } echo substr($result,0,100).PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GdtmP
function name:  (null)
number of ops:  32
compiled vars:  !0 = $bigStr, !1 = $bigQuery, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 'x'
          2        SEND_VAL                                                 443000
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   35     5        ROPE_INIT                                     3  ~6      'INSERT+INTO+%60emr_doc_file%60+%28%60emr_doc_id%60%2C+%60edf_file%60%2C+%60edf_mimetype%60%2C+%60edf_upload_date%60%29+VALUES+%28%27108%27%2C+x%27'
          6        ROPE_ADD                                      1  ~6      ~6, !0
          7        ROPE_END                                      2  ~5      ~6, '%27%2C+%27application%2Fpdf%27%2C+1490978009%29'
          8        ASSIGN                                                   !1, ~5
   36     9        INIT_FCALL                                               'formatsql'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 <array>
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !2, $9
   37    14        TYPE_CHECK                                    2          !2
         15      > JMPZ                                                     ~11, ->24
   38    16    >   NEW                                              $12     'Exception'
         17        INIT_FCALL                                               'preg_last_error'
         18        DO_ICALL                                         $13     
         19        CONCAT                                           ~14     'preg+error%3A+', $13
         20        CONCAT                                           ~15     ~14, '%0Asee%3A+http%3A%2F%2Fphp.net%2Fmanual%2Fen%2Fpcre.constants.php%23117743'
         21        SEND_VAL_EX                                              ~15
         22        DO_FCALL                                      0          
         23      > THROW                                         0          $12
   40    24    >   INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 0
         27        SEND_VAL                                                 100
         28        DO_ICALL                                         $17     
         29        CONCAT                                           ~18     $17, '%0A'
         30        ECHO                                                     ~18
         31      > RETURN                                                   1

Function formatsql:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GdtmP
function name:  FormatSql
number of ops:  12
compiled vars:  !0 = $query, !1 = $params, !2 = $patt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    3     2        ASSIGN                                                   !2, '%7E++%28%5B%27%22%60%5D%29+%23+capture+this+quote+character%0A++%28%3F%3A%5C%5C.%7C%28%3F%21%5C1%29.%29%2A+%23+any+escaped+character%2C+or%0A+++++++++++++++++++%23+any+character+that+isn%27t+the+captured+one%0A++%5C1++++++%23+the+captured+quote+again%0A++%28%2ASKIP%29%28%2AFAIL%29+++%23+ignore+this%0A++%7C%0A++%5C%3F%5C%3F%3F+++%23+one+or+two+question+marks%0A++%7C%0A++%3A%3A%3F%5Cw%2B++%23+word+characters+marked+with+one+or+two+colons%7Ex'
   13     3        INIT_FCALL                                               'preg_replace_callback'
          4        SEND_VAR                                                 !2
          5        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          6        BIND_LEXICAL                                             ~4, !1
   30     7        SEND_VAL                                                 ~4
          8        SEND_VAR                                                 !0
   13     9        DO_ICALL                                         $5      
   30    10      > RETURN                                                   $5
   31    11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
6 jumps found. (Code = 188) Position 1 = 18, Position 2 = 26, Position 3 = 34, Position 4 = 48, Position 5 = 62, Position 6 = 9
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 46
Branch analysis from position: 38
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 60
Branch analysis from position: 52
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 34
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 48
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
Branch analysis from position: 48
Branch analysis from position: 34
Branch analysis from position: 26
Branch analysis from position: 18
filename:       /in/GdtmP
function name:  {closure}
number of ops:  68
compiled vars:  !0 = $matches, !1 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   14     2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      !0, 1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->7
          5    >   FETCH_DIM_R                                      ~4      !0, 0
          6      > RETURN                                                   ~4
   15     7    >   FETCH_DIM_R                                      ~5      !0, 1
          8      > SWITCH_STRING                                            ~5, [ '%3F':->18, '%3F%3F':->26, '%3A':->34, '%3A%3A':->48, ], ->62
   16     9    >   CASE                                                     ~5, '%3F'
         10      > JMPNZ                                                    ~6, ->18
   19    11    >   CASE                                                     ~5, '%3F%3F'
         12      > JMPNZ                                                    ~6, ->26
   22    13    >   CASE                                                     ~5, '%3A'
         14      > JMPNZ                                                    ~6, ->34
   25    15    >   CASE                                                     ~5, '%3A%3A'
         16      > JMPNZ                                                    ~6, ->48
         17    > > JMP                                                      ->62
   17    18    >   BOOL_NOT                                         ~7      !1
         19      > JMPZ                                                     ~7, ->24
         20    >   NEW                                              $8      'DomainException'
         21        SEND_VAL_EX                                              'Not+enough+params'
         22        DO_FCALL                                      0          
         23      > THROW                                         0          $8
   18    24    >   FREE                                                     ~5
         25      > RETURN                                                   '%2Asnip%2A'
   20    26    >   BOOL_NOT                                         ~10     !1
         27      > JMPZ                                                     ~10, ->32
         28    >   NEW                                              $11     'DomainException'
         29        SEND_VAL_EX                                              'Not+enough+params'
         30        DO_FCALL                                      0          
         31      > THROW                                         0          $11
   21    32    >   FREE                                                     ~5
         33      > RETURN                                                   '%2Asnip%2A'
   23    34    >   FETCH_DIM_R                                      ~13     !0, 2
         35        ARRAY_KEY_EXISTS                                 ~14     ~13, !1
         36        BOOL_NOT                                         ~15     ~14
         37      > JMPZ                                                     ~15, ->46
         38    >   NEW                                              $16     'DomainException'
         39        ROPE_INIT                                     3  ~19     '%22'
         40        FETCH_DIM_R                                      ~17     !0, 2
         41        ROPE_ADD                                      1  ~19     ~19, ~17
         42        ROPE_END                                      2  ~18     ~19, '%22+param+not+provided'
         43        SEND_VAL_EX                                              ~18
         44        DO_FCALL                                      0          
         45      > THROW                                         0          $16
   24    46    >   FREE                                                     ~5
         47      > RETURN                                                   '%2Asnip%2A'
   26    48    >   FETCH_DIM_R                                      ~22     !0, 2
         49        ARRAY_KEY_EXISTS                                 ~23     ~22, !1
         50        BOOL_NOT                                         ~24     ~23
         51      > JMPZ                                                     ~24, ->60
         52    >   NEW                                              $25     'DomainException'
         53        ROPE_INIT                                     3  ~28     '%22'
         54        FETCH_DIM_R                                      ~26     !0, 2
         55        ROPE_ADD                                      1  ~28     ~28, ~26
         56        ROPE_END                                      2  ~27     ~28, '%22+param+not+provided'
         57        SEND_VAL_EX                                              ~27
         58        DO_FCALL                                      0          
         59      > THROW                                         0          $25
   27    60    >   FREE                                                     ~5
         61      > RETURN                                                   '%2Asnip%2A'
         62    >   FREE                                                     ~5
   29    63        NEW                                              $31     'Exception'
         64        SEND_VAL_EX                                              'Bad+regex'
         65        DO_FCALL                                      0          
         66      > THROW                                         0          $31
   30    67*     > RETURN                                                   null

End of Dynamic Function 0

End of function formatsql

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.03 ms | 1018 KiB | 18 Q