3v4l.org

run code in 300+ PHP versions simultaneously
<?php try { $db = DatabasePDOTest::getInstance(); var_dump($db->connectToDatabase('test')); } catch (Exception $ex) { var_dump($ex); } echo "end"; final class DatabasePDOTest extends PDO { const STANDARD_DB = 'standard'; const DBHOST = 'host'; const DBUSER = 'user'; const DBPASS = 'password'; const DBNAME = 'dbname'; private static $_instance = null; private $_persistent = false; private $_databases = array(); private $_databaseHost = null; private $_databaseUser = null; private $_databasePass = null; private $_database = null; private $_charset = 'utf8'; public function __construct($persistent = false, $pathAddition = null, $databaseIdentifier = null) { $this->_loadConfig($pathAddition); $this->_persistent = $persistent; if (! is_null($databaseIdentifier)) { $this->connectToDatabase($databaseIdentifier); } else { if (array_key_exists(self::STANDARD_DB, $this->_databases)) { $this->connectToDatabase($this->_databases[self::STANDARD_DB]); } else { throw new InvalidArgumentException('no database set and no standard found'); } } } public function connectToDatabase($name) { if (! array_key_exists($name, $this->_databases)) { throw new UnexpectedValueException('identifier "' . $name . '" for database does not exist!'); } $this->_databaseHost = $this->_databases[$name][self::DBHOST]; $this->_databaseUser = $this->_databases[$name][self::DBUSER]; $this->_databasePass = $this->_databases[$name][self::DBPASS]; $this->_database = $this->_databases[$name][self::DBNAME]; return $this->connect(); } public static function getInstance($persistent = true, $pathAddition = null, $databaseIdentifier = null) { if (self::$_instance === null) { self::$_instance = new DatabasePDOTest($persistent, $pathAddition, $databaseIdentifier); } return self::$_instance; } public function getOneResultFlat(PDOStatement $stmt) { $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $return = array(); array_walk_recursive($results, function ($a) use (&$return) { $return[] = $a; }); return $return; } public function getMultipleResultFlat(PDOStatement $stmt) { $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $returnArray = array(); foreach ($results as $value) { foreach ($value as $key => $var) { $returnArray[$key][] = $var; } } return $returnArray; } public function getResultArray($sql) { $stmt = $this->query($sql); return $stmt->fetchAll(PDO::FETCH_ASSOC); } private function connect() { parent::__construct(sprintf('mysql:host=%1$s;dbname=%2$s;charset=%3$s', $this->_databaseHost, $this->_database, $this->_charset), $this->_databaseUser, $this->_databasePass, array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => $this->_persistent )); return true; } private function _loadConfig($pathAddition = null) { $this->_databases = array( "test" => array( "host" => "localhost", "user" => "test", "password" => "test", "dbname" => "test" ), "standard" => "test" ); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
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/qPgc4
function name:  (null)
number of ops:  16
compiled vars:  !0 = $db, !1 = $ex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_STATIC_METHOD_CALL                                  'DatabasePDOTest', 'getInstance'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
    4     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'connectToDatabase'
          5        SEND_VAL_EX                                              'test'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > JMP                                                      ->14
    5    10  E > > CATCH                                       last         'Exception'
    6    11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
    8    14    >   ECHO                                                     'end'
  129    15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FqPgc4%3A81%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a, !1 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   82     2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  !0
   83     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FqPgc4%3A81%240

Class DatabasePDOTest:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/qPgc4
function name:  __construct
number of ops:  30
compiled vars:  !0 = $persistent, !1 = $pathAddition, !2 = $databaseIdentifier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV_INIT                                        !0      <false>
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   41     3        INIT_METHOD_CALL                                         '_loadConfig'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   42     6        ASSIGN_OBJ                                               '_persistent'
          7        OP_DATA                                                  !0
   44     8        TYPE_CHECK                                    2  ~5      !2
          9        BOOL_NOT                                         ~6      ~5
         10      > JMPZ                                                     ~6, ->15
   45    11    >   INIT_METHOD_CALL                                         'connectToDatabase'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
         14      > JMP                                                      ->29
   47    15    >   FETCH_OBJ_R                                      ~8      '_databases'
         16        ARRAY_KEY_EXISTS                                         'standard', ~8
         17      > JMPZ                                                     ~9, ->25
   48    18    >   INIT_METHOD_CALL                                         'connectToDatabase'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_OBJ_FUNC_ARG                               $10     '_databases'
         21        FETCH_DIM_FUNC_ARG                               $11     $10, 'standard'
         22        SEND_FUNC_ARG                                            $11
         23        DO_FCALL                                      0          
         24      > JMP                                                      ->29
   50    25    >   NEW                                              $13     'InvalidArgumentException'
         26        SEND_VAL_EX                                              'no+database+set+and+no+standard+found'
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $13
   53    29    > > RETURN                                                   null

End of function __construct

Function connecttodatabase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  connectToDatabase
number of ops:  35
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   57     1        FETCH_OBJ_R                                      ~1      '_databases'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->11
   58     5    >   NEW                                              $4      'UnexpectedValueException'
          6        CONCAT                                           ~5      'identifier+%22', !0
          7        CONCAT                                           ~6      ~5, '%22+for+database+does+not+exist%21'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   61    11    >   FETCH_OBJ_R                                      ~9      '_databases'
         12        FETCH_DIM_R                                      ~10     ~9, !0
         13        FETCH_DIM_R                                      ~11     ~10, 'host'
         14        ASSIGN_OBJ                                               '_databaseHost'
         15        OP_DATA                                                  ~11
   62    16        FETCH_OBJ_R                                      ~13     '_databases'
         17        FETCH_DIM_R                                      ~14     ~13, !0
         18        FETCH_DIM_R                                      ~15     ~14, 'user'
         19        ASSIGN_OBJ                                               '_databaseUser'
         20        OP_DATA                                                  ~15
   63    21        FETCH_OBJ_R                                      ~17     '_databases'
         22        FETCH_DIM_R                                      ~18     ~17, !0
         23        FETCH_DIM_R                                      ~19     ~18, 'password'
         24        ASSIGN_OBJ                                               '_databasePass'
         25        OP_DATA                                                  ~19
   64    26        FETCH_OBJ_R                                      ~21     '_databases'
         27        FETCH_DIM_R                                      ~22     ~21, !0
         28        FETCH_DIM_R                                      ~23     ~22, 'dbname'
         29        ASSIGN_OBJ                                               '_database'
         30        OP_DATA                                                  ~23
   66    31        INIT_METHOD_CALL                                         'connect'
         32        DO_FCALL                                      0  $24     
         33      > RETURN                                                   $24
   67    34*     > RETURN                                                   null

End of function connecttodatabase

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/qPgc4
function name:  getInstance
number of ops:  16
compiled vars:  !0 = $persistent, !1 = $pathAddition, !2 = $databaseIdentifier
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV_INIT                                        !0      <true>
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   71     3        FETCH_STATIC_PROP_R          unknown             ~3      '_instance'
          4        TYPE_CHECK                                    2          ~3
          5      > JMPZ                                                     ~4, ->13
   72     6    >   NEW                                              $6      'DatabasePDOTest'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
         11        ASSIGN_STATIC_PROP                                       '_instance'
         12        OP_DATA                                                  $6
   74    13    >   FETCH_STATIC_PROP_R          unknown             ~8      '_instance'
         14      > RETURN                                                   ~8
   75    15*     > RETURN                                                   null

End of function getinstance

Function getoneresultflat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  getOneResultFlat
number of ops:  14
compiled vars:  !0 = $stmt, !1 = $results, !2 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
   79     1        INIT_METHOD_CALL                                         !0, 'fetchAll'
          2        SEND_VAL_EX                                              2
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   80     5        ASSIGN                                                   !2, <array>
   81     6        INIT_FCALL                                               'array_walk_recursive'
          7        SEND_REF                                                 !1
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FqPgc4%3A81%240'
          9        BIND_LEXICAL                                             ~6, !2
   83    10        SEND_VAL                                                 ~6
         11        DO_ICALL                                                 
   84    12      > RETURN                                                   !2
   85    13*     > RETURN                                                   null

End of function getoneresultflat

Function getmultipleresultflat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 15
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/qPgc4
function name:  getMultipleResultFlat
number of ops:  20
compiled vars:  !0 = $stmt, !1 = $results, !2 = $returnArray, !3 = $value, !4 = $var, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   89     1        INIT_METHOD_CALL                                         !0, 'fetchAll'
          2        SEND_VAL_EX                                              2
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   90     5        ASSIGN                                                   !2, <array>
   92     6      > FE_RESET_R                                       $9      !1, ->17
          7    > > FE_FETCH_R                                               $9, !3, ->17
   93     8    > > FE_RESET_R                                       $10     !3, ->15
          9    > > FE_FETCH_R                                       ~11     $10, !4, ->15
         10    >   ASSIGN                                                   !5, ~11
   94    11        FETCH_DIM_W                                      $13     !2, !5
         12        ASSIGN_DIM                                               $13
         13        OP_DATA                                                  !4
   93    14      > JMP                                                      ->9
         15    >   FE_FREE                                                  $10
   92    16      > JMP                                                      ->7
         17    >   FE_FREE                                                  $9
   98    18      > RETURN                                                   !2
   99    19*     > RETURN                                                   null

End of function getmultipleresultflat

Function getresultarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  getResultArray
number of ops:  10
compiled vars:  !0 = $sql, !1 = $stmt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  101     0  E >   RECV                                             !0      
  103     1        INIT_METHOD_CALL                                         'query'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
  104     5        INIT_METHOD_CALL                                         !1, 'fetchAll'
          6        SEND_VAL_EX                                              2
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
  105     9*     > RETURN                                                   null

End of function getresultarray

Function connect:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  connect
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   INIT_STATIC_METHOD_CALL                                  
          1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 'mysql%3Ahost%3D%251%24s%3Bdbname%3D%252%24s%3Bcharset%3D%253%24s'
          3        FETCH_OBJ_R                                      ~0      '_databaseHost'
          4        SEND_VAL                                                 ~0
          5        FETCH_OBJ_R                                      ~1      '_database'
          6        SEND_VAL                                                 ~1
          7        FETCH_OBJ_R                                      ~2      '_charset'
          8        SEND_VAL                                                 ~2
          9        DO_ICALL                                         $3      
         10        SEND_VAR_NO_REF_EX                                       $3
         11        CHECK_FUNC_ARG                                           
         12        FETCH_OBJ_FUNC_ARG                               $4      '_databaseUser'
         13        SEND_FUNC_ARG                                            $4
         14        CHECK_FUNC_ARG                                           
         15        FETCH_OBJ_FUNC_ARG                               $5      '_databasePass'
         16        SEND_FUNC_ARG                                            $5
  110    17        INIT_ARRAY                                       ~6      <false>, 20
         18        ADD_ARRAY_ELEMENT                                ~6      2, 3
  112    19        FETCH_OBJ_R                                      ~7      '_persistent'
         20        ADD_ARRAY_ELEMENT                                ~6      ~7, 12
         21        SEND_VAL_EX                                              ~6
         22        DO_FCALL                                      0          
  114    23      > RETURN                                                   <true>
  115    24*     > RETURN                                                   null

End of function connect

Function _loadconfig:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPgc4
function name:  _loadConfig
number of ops:  4
compiled vars:  !0 = $pathAddition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  117     0  E >   RECV_INIT                                        !0      null
  119     1        ASSIGN_OBJ                                               '_databases'
  121     2        OP_DATA                                                  <array>
  128     3      > RETURN                                                   null

End of function _loadconfig

End of class DatabasePDOTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.26 ms | 961 KiB | 20 Q