3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class DB { private static $DBCONN = NULL; private static $OLog = NULL; private static function DBConnection() { if ( self::$DBCONN === NULL) { self::$DBCONN = new PDO('mysql:host=localhost;dbname=test', 'root', ''); } return self::$DBCONN; } public static function setLogger(Logger $logger) { self::$OLog = $logger; } public static function insertWithParams($SQL, $params){ try { self::$OLog->writeToFile( LogType::SQL, $SQL); self::$OLog->writeToFile( LogType::SQL_PARAMS, implode(",", $params)); $statement = self::DBConnection()->prepare($SQL); foreach ($params as $param => &$value) { $statement->bindParam($param, $value, PDO::PARAM_STR); echo 'Param = ' . $param . ' - ' . $value . '</br>'; } $retour = $statement->execute(); self::$OLog->writeToFile( LogType::SUCCESS); return $retour; } catch (Exception $e) { self::$OLog->writeToFile( LogType::ERROR . $e->getMessage()); return $e->getMessage(); } } } class Logger { private $fileToWrite = NULL; private function setFileToWrite(string $file) { if (file_exists($file)) { $this->fileToWrite = $file; return TRUE; } else { throw new Exception("Le fichier $file n existe pas."); } } public static function createLogger(string $fileToWrite) { $oLogger = new Logger(); try { if ($oLogger->setFileToWrite($fileToWrite)) { return $oLogger; } } catch (Exception $e) { //return $e->getMessage(); return NULL; } } public function writeToFile(string $LogType, string $message = '') : bool { //var_dump(debug_backtrace()); if (file_put_contents( $this->fileToWrite, date("Y-m-d h:i:sa") . ' - ' . 'From ' . debug_backtrace()[2]['class'] . ' - ' . $LogType . $message . PHP_EOL, FILE_APPEND) != FALSE ) { return TRUE; } else { return FALSE; } } } $oLogger = Logger::createLogger('log.txt'); DB::setLogger($oLogger);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKPCV
function name:  (null)
number of ops:  8
compiled vars:  !0 = $oLogger
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   INIT_STATIC_METHOD_CALL                                  'Logger', 'createLogger'
          1        SEND_VAL                                                 'log.txt'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   90     4        INIT_STATIC_METHOD_CALL                                  'DB', 'setLogger'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class DB:
Function dbconnection:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/OKPCV
function name:  DBConnection
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'DBCONN'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->10
   10     3    >   NEW                                              $3      'PDO'
          4        SEND_VAL_EX                                              'mysql%3Ahost%3Dlocalhost%3Bdbname%3Dtest'
          5        SEND_VAL_EX                                              'root'
          6        SEND_VAL_EX                                              ''
          7        DO_FCALL                                      0          
          8        ASSIGN_STATIC_PROP                                       'DBCONN'
          9        OP_DATA                                                  $3
   12    10    >   FETCH_STATIC_PROP_R          unknown             ~5      'DBCONN'
         11      > RETURN                                                   ~5
   13    12*     > RETURN                                                   null

End of function dbconnection

Function setlogger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKPCV
function name:  setLogger
number of ops:  4
compiled vars:  !0 = $logger
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN_STATIC_PROP                                       'OLog'
          2        OP_DATA                                                  !0
   17     3      > RETURN                                                   null

End of function setlogger

Function insertwithparams:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 25, Position 2 = 38
Branch analysis from position: 25
2 jumps found. (Code = 126) Position 1 = 26, Position 2 = 38
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Found catch point at position: 49
Branch analysis from position: 49
2 jumps found. (Code = 107) Position 1 = 50, Position 2 = -2
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKPCV
function name:  insertWithParams
number of ops:  62
compiled vars:  !0 = $SQL, !1 = $params, !2 = $statement, !3 = $value, !4 = $param, !5 = $retour, !6 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        FETCH_STATIC_PROP_R          unknown             ~7      'OLog'
          3        INIT_METHOD_CALL                                         ~7, 'writeToFile'
          4        FETCH_CLASS_CONSTANT                             ~8      'LogType', 'SQL'
          5        SEND_VAL_EX                                              ~8
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
   22     8        FETCH_STATIC_PROP_R          unknown             ~10     'OLog'
          9        INIT_METHOD_CALL                                         ~10, 'writeToFile'
         10        FETCH_CLASS_CONSTANT                             ~11     'LogType', 'SQL_PARAMS'
         11        SEND_VAL_EX                                              ~11
         12        INIT_FCALL                                               'implode'
         13        SEND_VAL                                                 '%2C'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $12     
         16        SEND_VAR_NO_REF_EX                                       $12
         17        DO_FCALL                                      0          
   24    18        INIT_STATIC_METHOD_CALL                                  'DBConnection'
         19        DO_FCALL                                      0  $14     
         20        INIT_METHOD_CALL                                         $14, 'prepare'
         21        SEND_VAR_EX                                              !0
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !2, $15
   25    24      > FE_RESET_RW                                      $17     !1, ->38
         25    > > FE_FETCH_RW                                      ~18     $17, !3, ->38
         26    >   ASSIGN                                                   !4, ~18
   26    27        INIT_METHOD_CALL                                         !2, 'bindParam'
         28        SEND_VAR_EX                                              !4
         29        SEND_VAR_EX                                              !3
         30        SEND_VAL_EX                                              2
         31        DO_FCALL                                      0          
   27    32        CONCAT                                           ~21     'Param+%3D+', !4
         33        CONCAT                                           ~22     ~21, '+-+'
         34        CONCAT                                           ~23     ~22, !3
         35        CONCAT                                           ~24     ~23, '%3C%2Fbr%3E'
         36        ECHO                                                     ~24
   25    37      > JMP                                                      ->25
         38    >   FE_FREE                                                  $17
   30    39        INIT_METHOD_CALL                                         !2, 'execute'
         40        DO_FCALL                                      0  $25     
         41        ASSIGN                                                   !5, $25
   31    42        FETCH_STATIC_PROP_R          unknown             ~27     'OLog'
         43        INIT_METHOD_CALL                                         ~27, 'writeToFile'
         44        FETCH_CLASS_CONSTANT                             ~28     'LogType', 'SUCCESS'
         45        SEND_VAL_EX                                              ~28
         46        DO_FCALL                                      0          
   32    47      > RETURN                                                   !5
         48*       JMP                                                      ->61
   33    49  E > > CATCH                                       last         'Exception'
   34    50    >   FETCH_STATIC_PROP_R          unknown             ~30     'OLog'
         51        INIT_METHOD_CALL                                         ~30, 'writeToFile'
         52        FETCH_CLASS_CONSTANT                             ~31     'LogType', 'ERROR'
         53        INIT_METHOD_CALL                                         !6, 'getMessage'
         54        DO_FCALL                                      0  $32     
         55        CONCAT                                           ~33     ~31, $32
         56        SEND_VAL_EX                                              ~33
         57        DO_FCALL                                      0          
   35    58        INIT_METHOD_CALL                                         !6, 'getMessage'
         59        DO_FCALL                                      0  $35     
         60      > RETURN                                                   $35
   39    61*     > RETURN                                                   null

End of function insertwithparams

End of class DB.

Class Logger:
Function setfiletowrite:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/OKPCV
function name:  setFileToWrite
number of ops:  17
compiled vars:  !0 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_FCALL                                               'file_exists'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > JMPZ                                                     $1, ->9
   49     5    >   ASSIGN_OBJ                                               'fileToWrite'
          6        OP_DATA                                                  !0
   50     7      > RETURN                                                   <true>
          8*       JMP                                                      ->16
   52     9    >   NEW                                              $3      'Exception'
         10        ROPE_INIT                                     3  ~5      'Le+fichier+'
         11        ROPE_ADD                                      1  ~5      ~5, !0
         12        ROPE_END                                      2  ~4      ~5, '+n+existe+pas.'
         13        SEND_VAL_EX                                              ~4
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $3
   54    16*     > RETURN                                                   null

End of function setfiletowrite

Function createlogger:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 10
Branch analysis from position: 10
2 jumps found. (Code = 107) Position 1 = 11, Position 2 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKPCV
function name:  createLogger
number of ops:  13
compiled vars:  !0 = $fileToWrite, !1 = $oLogger, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   57     1        NEW                                              $3      'Logger'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   59     4        INIT_METHOD_CALL                                         !1, 'setFileToWrite'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $6      
          7      > JMPZ                                                     $6, ->9
   60     8    > > RETURN                                                   !1
          9    > > JMP                                                      ->12
   62    10  E > > CATCH                                       last         'Exception'
   64    11    > > RETURN                                                   null
   67    12    > > RETURN                                                   null

End of function createlogger

Function writetofile:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OKPCV
function name:  writeToFile
number of ops:  29
compiled vars:  !0 = $LogType, !1 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
   72     2        INIT_FCALL                                               'file_put_contents'
   73     3        FETCH_OBJ_R                                      ~2      'fileToWrite'
          4        SEND_VAL                                                 ~2
   74     5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'Y-m-d+h%3Ai%3Asa'
          7        DO_ICALL                                         $3      
          8        CONCAT                                           ~4      $3, '+-+'
   75     9        CONCAT                                           ~5      ~4, 'From+'
         10        INIT_FCALL                                               'debug_backtrace'
         11        DO_ICALL                                         $6      
         12        FETCH_DIM_R                                      ~7      $6, 2
         13        FETCH_DIM_R                                      ~8      ~7, 'class'
         14        CONCAT                                           ~9      ~5, ~8
         15        CONCAT                                           ~10     ~9, '+-+'
   76    16        CONCAT                                           ~11     ~10, !0
   77    17        CONCAT                                           ~12     ~11, !1
   78    18        CONCAT                                           ~13     ~12, '%0A'
         19        SEND_VAL                                                 ~13
         20        SEND_VAL                                                 8
         21        DO_ICALL                                         $14     
   79    22        BOOL                                             ~15     $14
         23      > JMPZ                                                     ~15, ->26
   81    24    > > RETURN                                                   <true>
         25*       JMP                                                      ->27
   83    26    > > RETURN                                                   <false>
   85    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function writetofile

End of class Logger.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.95 ms | 1412 KiB | 23 Q