3v4l.org

run code in 300+ PHP versions simultaneously
<?php // DBLogger.php class DBLogger { private $enabled; private $operations; private $ignoredTables; public function __construct() { $this->enabled = false; $this->operations = null; $this->ignoredTables = null; } public function enable() { $this->enabled = true; return $this; } public function disable() { $this->enabled = false; return $this; } public function operations($operations) { $this->operations = $operations; return $this; } public function ignoreTables($tables) { $this->ignoredTables = $tables; return $this; } public function log($query) { if(!$this->enabled) return; $queryParts = explode(" ", $query); $queryCommand = $queryParts[0]; if($this->operations === null || strripos($this->operations, $queryCommand) !== false) { $tables = $this->ignoredTables === null ? array() : explode(",", $this->ignoredTables); $numOfTables = count($tables); for($i=0; $i<$numOfTables; $i++) { $tableName = str_replace(" ", "", $tables[$i]); if(strpos($query, $tableName) !== false) { return; } } $file = "queries_".date("Y-d-m").".sql"; $this->writeToFile($file, $query); } return $this; } private function writeToFile($file, $query) { $dir = dirname(__FILE__)."/logs/"; $content = ''; if(file_exists($dir.$file)) { $content = file_get_contents($dir.$file)."\n\n"; } $content .= $query.";"; file_put_contents($dir.$file, $content); } } global $dblogger; $dblogger = new DBLogger();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  (null)
number of ops:  5
compiled vars:  !0 = $dblogger
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   BIND_GLOBAL                                              !0, 'dblogger'
   62     1        NEW                                              $1      'DBLogger'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
          4      > RETURN                                                   1

Class DBLogger:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN_OBJ                                               'enabled'
          1        OP_DATA                                                  <false>
   13     2        ASSIGN_OBJ                                               'operations'
          3        OP_DATA                                                  null
   14     4        ASSIGN_OBJ                                               'ignoredTables'
          5        OP_DATA                                                  null
   15     6      > RETURN                                                   null

End of function __construct

Function enable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  enable
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN_OBJ                                               'enabled'
          1        OP_DATA                                                  <true>
   18     2        FETCH_THIS                                       ~1      
          3      > RETURN                                                   ~1
   19     4*     > RETURN                                                   null

End of function enable

Function disable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  disable
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN_OBJ                                               'enabled'
          1        OP_DATA                                                  <false>
   22     2        FETCH_THIS                                       ~1      
          3      > RETURN                                                   ~1
   23     4*     > RETURN                                                   null

End of function disable

Function operations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  operations
number of ops:  6
compiled vars:  !0 = $operations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN_OBJ                                               'operations'
          2        OP_DATA                                                  !0
   26     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   27     5*     > RETURN                                                   null

End of function operations

Function ignoretables:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhMjQ
function name:  ignoreTables
number of ops:  6
compiled vars:  !0 = $tables
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        ASSIGN_OBJ                                               'ignoredTables'
          2        OP_DATA                                                  !0
   30     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   31     5*     > RETURN                                                   null

End of function ignoretables

Function log:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 66
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 39
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 39
Branch analysis from position: 56
Branch analysis from position: 39
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 66
Branch analysis from position: 22
filename:       /in/WhMjQ
function name:  log
number of ops:  69
compiled vars:  !0 = $query, !1 = $queryParts, !2 = $queryCommand, !3 = $tables, !4 = $numOfTables, !5 = $i, !6 = $tableName, !7 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        FETCH_OBJ_R                                      ~8      'enabled'
          2        BOOL_NOT                                         ~9      ~8
          3      > JMPZ                                                     ~9, ->5
          4    > > RETURN                                                   null
   34     5    >   INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '+'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !1, $10
   35    10        FETCH_DIM_R                                      ~12     !1, 0
         11        ASSIGN                                                   !2, ~12
   36    12        FETCH_OBJ_R                                      ~14     'operations'
         13        TYPE_CHECK                                    2  ~15     ~14
         14      > JMPNZ_EX                                         ~15     ~15, ->22
         15    >   INIT_FCALL                                               'strripos'
         16        FETCH_OBJ_R                                      ~16     'operations'
         17        SEND_VAL                                                 ~16
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $17     
         20        TYPE_CHECK                                  1018  ~18     $17
         21        BOOL                                             ~15     ~18
         22    > > JMPZ                                                     ~15, ->66
   37    23    >   FETCH_OBJ_R                                      ~19     'ignoredTables'
         24        TYPE_CHECK                                    2          ~19
         25      > JMPZ                                                     ~20, ->28
         26    >   QM_ASSIGN                                        ~21     <array>
         27      > JMP                                                      ->34
         28    >   INIT_FCALL                                               'explode'
         29        SEND_VAL                                                 '%2C'
         30        FETCH_OBJ_R                                      ~22     'ignoredTables'
         31        SEND_VAL                                                 ~22
         32        DO_ICALL                                         $23     
         33        QM_ASSIGN                                        ~21     $23
         34    >   ASSIGN                                                   !3, ~21
   38    35        COUNT                                            ~25     !3
         36        ASSIGN                                                   !4, ~25
   39    37        ASSIGN                                                   !5, 0
         38      > JMP                                                      ->54
   40    39    >   INIT_FCALL                                               'str_replace'
         40        SEND_VAL                                                 '+'
         41        SEND_VAL                                                 ''
         42        FETCH_DIM_R                                      ~28     !3, !5
         43        SEND_VAL                                                 ~28
         44        DO_ICALL                                         $29     
         45        ASSIGN                                                   !6, $29
   41    46        INIT_FCALL                                               'strpos'
         47        SEND_VAR                                                 !0
         48        SEND_VAR                                                 !6
         49        DO_ICALL                                         $31     
         50        TYPE_CHECK                                  1018          $31
         51      > JMPZ                                                     ~32, ->53
   42    52    > > RETURN                                                   null
   39    53    >   PRE_INC                                                  !5
         54    >   IS_SMALLER                                               !5, !4
         55      > JMPNZ                                                    ~34, ->39
   45    56    >   INIT_FCALL                                               'date'
         57        SEND_VAL                                                 'Y-d-m'
         58        DO_ICALL                                         $35     
         59        CONCAT                                           ~36     'queries_', $35
         60        CONCAT                                           ~37     ~36, '.sql'
         61        ASSIGN                                                   !7, ~37
   46    62        INIT_METHOD_CALL                                         'writeToFile'
         63        SEND_VAR_EX                                              !7
         64        SEND_VAR_EX                                              !0
         65        DO_FCALL                                      0          
   48    66    >   FETCH_THIS                                       ~40     
         67      > RETURN                                                   ~40
   49    68*     > RETURN                                                   null

End of function log

Function writetofile:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/WhMjQ
function name:  writeToFile
number of ops:  27
compiled vars:  !0 = $file, !1 = $query, !2 = $dir, !3 = $content
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   51     2        INIT_FCALL                                               'dirname'
          3        SEND_VAL                                                 '%2Fin%2FWhMjQ'
          4        DO_ICALL                                         $4      
          5        CONCAT                                           ~5      $4, '%2Flogs%2F'
          6        ASSIGN                                                   !2, ~5
   52     7        ASSIGN                                                   !3, ''
   53     8        INIT_FCALL                                               'file_exists'
          9        CONCAT                                           ~8      !2, !0
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12      > JMPZ                                                     $9, ->19
   54    13    >   INIT_FCALL                                               'file_get_contents'
         14        CONCAT                                           ~10     !2, !0
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                         $11     
         17        CONCAT                                           ~12     $11, '%0A%0A'
         18        ASSIGN                                                   !3, ~12
   56    19    >   CONCAT                                           ~14     !1, '%3B'
         20        ASSIGN_OP                                     8          !3, ~14
   57    21        INIT_FCALL                                               'file_put_contents'
         22        CONCAT                                           ~16     !2, !0
         23        SEND_VAL                                                 ~16
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
   58    26      > RETURN                                                   null

End of function writetofile

End of class DBLogger.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.37 ms | 1408 KiB | 31 Q