3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Database { protected static $instance; protected $pdo; protected $lastExecute; protected function __construct() { $this->pdo = new PDO('sqlite::memory:'); } public static function instance() { if (null === self::$instance) { self::$instance = new self; } return self::$instance; } /** * @return PDOStatement|false */ public function run($sql, $args = []) { if (!$args) { return $this->pdo->query($sql); } if ($stmt = $this->pdo->prepare($sql)) { $this->lastExecute = $stmt->execute($args); } return $stmt; } /** * @return null|bool */ public function getLastExecute() { return $this->lastExecute; } 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 $db = Database::instance(); $db->run('SELECT ?', ['foo', 'bar']); var_dump($db->getLastExecute()); //false
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UbM1N
function name:  (null)
number of ops:  13
compiled vars:  !0 = $db
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   60     0  E >   INIT_STATIC_METHOD_CALL                                      'Database', 'instance'
          1        DO_FCALL                                          0  $1      
          2        ASSIGN                                                       !0, $1
   61     3        INIT_METHOD_CALL                                             !0, 'run'
          4        SEND_VAL_EX                                                  'SELECT+%3F'
          5        SEND_VAL_EX                                                  <array>
          6        DO_FCALL                                          0          
   62     7        INIT_FCALL                                                   'var_dump'
          8        INIT_METHOD_CALL                                             !0, 'getLastExecute'
          9        DO_FCALL                                          0  $4      
         10        SEND_VAR                                                     $4
         11        DO_ICALL                                                     
         12      > RETURN                                                       1

Class Database:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UbM1N
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   NEW                                                  $1      'PDO'
          1        SEND_VAL_EX                                                  'sqlite%3A%3Amemory%3A'
          2        DO_FCALL                                          0          
          3        ASSIGN_OBJ                                                   'pdo'
          4        OP_DATA                                                      $1
   12     5      > 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/UbM1N
function name:  instance
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   FETCH_STATIC_PROP_R              unknown             ~0      'instance'
          1        TYPE_CHECK                                        2          ~0
          2      > JMPZ                                                         ~1, ->7
   17     3    >   NEW                              self                $3      
          4        DO_FCALL                                          0          
          5        ASSIGN_STATIC_PROP                                           'instance'
          6        OP_DATA                                                      $3
   20     7    >   FETCH_STATIC_PROP_R              unknown             ~5      'instance'
          8      > RETURN                                                       ~5
   21     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 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/UbM1N
function name:  run
number of ops:  22
compiled vars:  !0 = $sql, !1 = $args, !2 = $stmt
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      <array>
   28     2        BOOL_NOT                                             ~3      !1
          3      > JMPZ                                                         ~3, ->9
   29     4    >   FETCH_OBJ_R                                          ~4      'pdo'
          5        INIT_METHOD_CALL                                             ~4, 'query'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0  $5      
          8      > RETURN                                                       $5
   31     9    >   FETCH_OBJ_R                                          ~6      'pdo'
         10        INIT_METHOD_CALL                                             ~6, 'prepare'
         11        SEND_VAR_EX                                                  !0
         12        DO_FCALL                                          0  $7      
         13        ASSIGN                                               ~8      !2, $7
         14      > JMPZ                                                         ~8, ->20
   32    15    >   INIT_METHOD_CALL                                             !2, 'execute'
         16        SEND_VAR_EX                                                  !1
         17        DO_FCALL                                          0  $10     
         18        ASSIGN_OBJ                                                   'lastExecute'
         19        OP_DATA                                                      $10
   35    20    > > RETURN                                                       !2
   36    21*     > RETURN                                                       null

End of function run

Function getlastexecute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UbM1N
function name:  getLastExecute
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                          ~0      'lastExecute'
          1      > RETURN                                                       ~0
   44     2*     > RETURN                                                       null

End of function getlastexecute

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/UbM1N
function name:  __call
number of ops:  23
compiled vars:  !0 = $method, !1 = $args
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   48     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
   50     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
   54    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
   55    22*     > RETURN                                                       null

End of function __call

End of class Database.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.62 ms | 3168 KiB | 15 Q