3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Database { protected static $instance; protected $pdo; protected function __construct() { static $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; $this->pdo = new PDO('sqlite::memory:', null, null, $opt); } public static function instance() { if (null === self::$instance) { self::$instance = new self; } return self::$instance; } public function run($sql, $args = []) { if (!$args) { return $this->query($sql); } $stmt = $this->prepare($sql); $stmt->execute($args); return $stmt; } public function __call($method, $args) { if (is_callable([$this->pdo, $method])) { //php 5.6+ variadic optimization (aka splat operator) return $this->pdo->$method(...$args); //PHP <= 5.5 //return call_user_func_array(array($this->pdo, $method), $args); } throw new \BadMethodCallException(sprintf('Unknown method PDO::%s called!', $method)); } } //RunTime code if (PHP_VERSION_ID >= 70100) { try { $db = Database::instance(); var_dump($db->run('SELECT ?', ['foo', 'bar'])->fetch()); } catch(\PDOException $e) { if ('execute' === $e->getTrace()[0]['function']) { echo 'PDO::execute() failed'; } //Handle the exception } } else { try { $db = Database::instance(); var_dump($db->run('SELECT ?', ['foo', 'bar'])->fetch()); } catch(\PDOException $e) { if ('execute' === $e->getTrace()[0]['function']) { echo 'PDO::execute() failed'; } //Handle the exception } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 1, Position 2 = 23
Branch analysis from position: 1
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Found catch point at position: 14
Branch analysis from position: 14
2 jumps found. (Code = 107) Position 1 = 15, Position 2 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 22
Found catch point at position: 36
Branch analysis from position: 36
2 jumps found. (Code = 107) Position 1 = 37, Position 2 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/fDnBI
function name:  (null)
number of ops:  45
compiled vars:  !0 = $db, !1 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E > > JMPZ                                                         <true>, ->23
   53     1    >   INIT_STATIC_METHOD_CALL                                      'Database', 'instance'
          2        DO_FCALL                                          0  $2      
          3        ASSIGN                                                       !0, $2
   54     4        INIT_FCALL                                                   'var_dump'
          5        INIT_METHOD_CALL                                             !0, 'run'
          6        SEND_VAL_EX                                                  'SELECT+%3F'
          7        SEND_VAL_EX                                                  <array>
          8        DO_FCALL                                          0  $4      
          9        INIT_METHOD_CALL                                             $4, 'fetch'
         10        DO_FCALL                                          0  $5      
         11        SEND_VAR                                                     $5
         12        DO_ICALL                                                     
         13      > JMP                                                          ->22
   55    14  E > > CATCH                                           last         'PDOException'
   56    15    >   INIT_METHOD_CALL                                             !1, 'getTrace'
         16        DO_FCALL                                          0  $7      
         17        FETCH_DIM_R                                          ~8      $7, 0
         18        FETCH_DIM_R                                          ~9      ~8, 'function'
         19        IS_IDENTICAL                                                 ~9, 'execute'
         20      > JMPZ                                                         ~10, ->22
   57    21    >   ECHO                                                         'PDO%3A%3Aexecute%28%29+failed'
   51    22    > > JMP                                                          ->44
   63    23    >   INIT_STATIC_METHOD_CALL                                      'Database', 'instance'
         24        DO_FCALL                                          0  $11     
         25        ASSIGN                                                       !0, $11
   64    26        INIT_FCALL                                                   'var_dump'
         27        INIT_METHOD_CALL                                             !0, 'run'
         28        SEND_VAL_EX                                                  'SELECT+%3F'
         29        SEND_VAL_EX                                                  <array>
         30        DO_FCALL                                          0  $13     
         31        INIT_METHOD_CALL                                             $13, 'fetch'
         32        DO_FCALL                                          0  $14     
         33        SEND_VAR                                                     $14
         34        DO_ICALL                                                     
         35      > JMP                                                          ->44
   65    36  E > > CATCH                                           last         'PDOException'
   66    37    >   INIT_METHOD_CALL                                             !1, 'getTrace'
         38        DO_FCALL                                          0  $16     
         39        FETCH_DIM_R                                          ~17     $16, 0
         40        FETCH_DIM_R                                          ~18     ~17, 'function'
         41        IS_IDENTICAL                                                 ~18, 'execute'
         42      > JMPZ                                                         ~19, ->44
   67    43    >   ECHO                                                         'PDO%3A%3Aexecute%28%29+failed'
   71    44    > > RETURN                                                       1

Class Database:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fDnBI
function name:  __construct
number of ops:  10
compiled vars:  !0 = $opt
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   BIND_STATIC                                                  !0
   13     1        NEW                                                  $2      'PDO'
          2        SEND_VAL_EX                                                  'sqlite%3A%3Amemory%3A'
          3        SEND_VAL_EX                                                  null
          4        SEND_VAL_EX                                                  null
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
          7        ASSIGN_OBJ                                                   'pdo'
          8        OP_DATA                                                      $2
   14     9      > RETURN                                                       null

End of function __construct

Function instance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/fDnBI
function name:  instance
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   FETCH_STATIC_PROP_R              unknown             ~0      'instance'
          1        TYPE_CHECK                                        2          ~0
          2      > JMPZ                                                         ~1, ->7
   19     3    >   NEW                              self                $3      
          4        DO_FCALL                                          0          
          5        ASSIGN_STATIC_PROP                                           'instance'
          6        OP_DATA                                                      $3
   22     7    >   FETCH_STATIC_PROP_R              unknown             ~5      'instance'
          8      > RETURN                                                       ~5
   23     9*     > RETURN                                                       null

End of function instance

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fDnBI
function name:  run
number of ops:  17
compiled vars:  !0 = $sql, !1 = $args, !2 = $stmt
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      <array>
   27     2        BOOL_NOT                                             ~3      !1
          3      > JMPZ                                                         ~3, ->8
   28     4    >   INIT_METHOD_CALL                                             'query'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0  $4      
          7      > RETURN                                                       $4
   30     8    >   INIT_METHOD_CALL                                             'prepare'
          9        SEND_VAR_EX                                                  !0
         10        DO_FCALL                                          0  $5      
         11        ASSIGN                                                       !2, $5
   31    12        INIT_METHOD_CALL                                             !2, 'execute'
         13        SEND_VAR_EX                                                  !1
         14        DO_FCALL                                          0          
   33    15      > RETURN                                                       !2
   34    16*     > RETURN                                                       null

End of function run

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/fDnBI
function name:  __call
number of ops:  23
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   38     2        INIT_FCALL                                                   'is_callable'
          3        FETCH_OBJ_R                                          ~2      'pdo'
          4        INIT_ARRAY                                           ~3      ~2
          5        ADD_ARRAY_ELEMENT                                    ~3      !0
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8      > JMPZ                                                         $4, ->15
   40     9    >   FETCH_OBJ_R                                          ~5      'pdo'
         10        INIT_METHOD_CALL                                             ~5, !0
         11        SEND_UNPACK                                                  !1
         12        CHECK_UNDEF_ARGS                                             
         13        DO_FCALL                                          1  $6      
         14      > RETURN                                                       $6
   44    15    >   NEW                                                  $7      'BadMethodCallException'
         16        ROPE_INIT                                         3  ~9      'Unknown+method+PDO%3A%3A'
         17        ROPE_ADD                                          1  ~9      ~9, !0
         18        ROPE_END                                          2  ~8      ~9, '+called%21'
         19        SEND_VAL_EX                                                  ~8
         20        DO_FCALL                                          0          
         21      > THROW                                             0          $7
   45    22*     > RETURN                                                       null

End of function __call

End of class Database.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.93 ms | 3135 KiB | 15 Q