3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config['sql_query_logging'] = [ 'enabled' => true, 'exclusions' => [ 'tables' => ['ci_sessions', 'system_log', 'jobs_log', 'error_log'], 'keywords' => ['select', 'show tables'] ] ]; $sqls = [ 'select * from table', 'show tables', 'update ci_sessions set some_col = some_val', 'update test set some_col = some_val', 'insert into test values(23, 45)', 'insert into ci_sessions values(1,2,3)', 'truncate ci_sessions' ]; foreach($sqls as $sql){ $result = array_merge( array_filter($config['sql_query_logging']['exclusions']['keywords'], fn($v) => preg_match('/\b'.$v.'\b/', $sql) === 1), array_filter($config['sql_query_logging']['exclusions']['tables'], function($table) use ($sql){ return preg_match('/\b(from|insert into|update|join|truncate|table)\s+'.$table.'\b/', $sql) === 1; }) ); if(empty($result)){ echo "Can log: ", $sql, PHP_EOL; // log here }else{ echo "Cannot log: ", $sql, PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/1gI2F
function name:  (null)
number of ops:  40
compiled vars:  !0 = $config, !1 = $sqls, !2 = $sql, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN_DIM                                               !0, 'sql_query_logging'
    4     1        OP_DATA                                                  <array>
   11     2        ASSIGN                                                   !1, <array>
   21     3      > FE_RESET_R                                       $6      !1, ->38
          4    > > FE_FETCH_R                                               $6, !2, ->38
   22     5    >   INIT_FCALL                                               'array_merge'
   23     6        INIT_FCALL                                               'array_filter'
          7        FETCH_DIM_R                                      ~7      !0, 'sql_query_logging'
          8        FETCH_DIM_R                                      ~8      ~7, 'exclusions'
          9        FETCH_DIM_R                                      ~9      ~8, 'keywords'
         10        SEND_VAL                                                 ~9
         11        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         12        BIND_LEXICAL                                             ~10, !2
         13        SEND_VAL                                                 ~10
         14        DO_ICALL                                         $11     
         15        SEND_VAR                                                 $11
   24    16        INIT_FCALL                                               'array_filter'
         17        FETCH_DIM_R                                      ~12     !0, 'sql_query_logging'
         18        FETCH_DIM_R                                      ~13     ~12, 'exclusions'
         19        FETCH_DIM_R                                      ~14     ~13, 'tables'
         20        SEND_VAL                                                 ~14
         21        DECLARE_LAMBDA_FUNCTION                          ~15     [1]
         22        BIND_LEXICAL                                             ~15, !2
   26    23        SEND_VAL                                                 ~15
   24    24        DO_ICALL                                         $16     
   26    25        SEND_VAR                                                 $16
   22    26        DO_ICALL                                         $17     
         27        ASSIGN                                                   !3, $17
   28    28        ISSET_ISEMPTY_CV                                         !3
         29      > JMPZ                                                     ~19, ->34
   29    30    >   ECHO                                                     'Can+log%3A+'
         31        ECHO                                                     !2
         32        ECHO                                                     '%0A'
   28    33      > JMP                                                      ->37
   32    34    >   ECHO                                                     'Cannot+log%3A+'
         35        ECHO                                                     !2
         36        ECHO                                                     '%0A'
   21    37    > > JMP                                                      ->4
         38    >   FE_FREE                                                  $6
   34    39      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1gI2F
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $v, !1 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'preg_match'
          3        CONCAT                                           ~2      '%2F%5Cb', !0
          4        CONCAT                                           ~3      ~2, '%5Cb%2F'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        IS_IDENTICAL                                     ~5      $4, 1
          9      > RETURN                                                   ~5
         10*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1gI2F
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $table, !1 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   25     2        INIT_FCALL                                               'preg_match'
          3        CONCAT                                           ~2      '%2F%5Cb%28from%7Cinsert+into%7Cupdate%7Cjoin%7Ctruncate%7Ctable%29%5Cs%2B', !0
          4        CONCAT                                           ~3      ~2, '%5Cb%2F'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        IS_IDENTICAL                                     ~5      $4, 1
          9      > RETURN                                                   ~5
   26    10*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.58 ms | 1017 KiB | 16 Q