3v4l.org

run code in 300+ PHP versions simultaneously
<?php // ----------------------------------- script1.php -------------- $provider = function() { $instance = new PDO('mysql:......;charset=utf8', 'username', 'password'); $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $instance; }; $factory = new StructureFactory( $provider ); $something = $factory->create('Something'); $foobar = $factory->create('Foobar'); // ----------------------------------- script2.php -------------- class StructureFactory { protected $provider = null; protected $connection = null; public function __construct( callable $provider ) { $this->provider = $provider; } public function create( $name) { if ( $this->connection === null ) { $this->connection = call_user_func( $this->provider ); } return new $name( $this->connection ); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o1Km6
function name:  (null)
number of ops:  15
compiled vars:  !0 = $provider, !1 = $factory, !2 = $something, !3 = $foobar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fo1Km6%3A4%240'
          1        ASSIGN                                                   !0, ~4
   12     2        NEW                                              $6      'StructureFactory'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   16     6        INIT_METHOD_CALL                                         !1, 'create'
          7        SEND_VAL_EX                                              'Something'
          8        DO_FCALL                                      0  $9      
          9        ASSIGN                                                   !2, $9
   17    10        INIT_METHOD_CALL                                         !1, 'create'
         11        SEND_VAL_EX                                              'Foobar'
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !3, $11
   43    14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fo1Km6%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o1Km6
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   NEW                                              $1      'PDO'
          1        SEND_VAL_EX                                              'mysql%3A......%3Bcharset%3Dutf8'
          2        SEND_VAL_EX                                              'username'
          3        SEND_VAL_EX                                              'password'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
    7     6        INIT_METHOD_CALL                                         !0, 'setAttribute'
          7        SEND_VAL_EX                                              3
          8        SEND_VAL_EX                                              2
          9        DO_FCALL                                      0          
    8    10        INIT_METHOD_CALL                                         !0, 'setAttribute'
         11        SEND_VAL_EX                                              20
         12        SEND_VAL_EX                                              <false>
         13        DO_FCALL                                      0          
    9    14      > RETURN                                                   !0
   10    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fo1Km6%3A4%240

Class StructureFactory:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o1Km6
function name:  __construct
number of ops:  4
compiled vars:  !0 = $provider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        ASSIGN_OBJ                                               'provider'
          2        OP_DATA                                                  !0
   32     3      > RETURN                                                   null

End of function __construct

Function create:
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
filename:       /in/o1Km6
function name:  create
number of ops:  17
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        FETCH_OBJ_R                                      ~1      'connection'
          2        TYPE_CHECK                                    2          ~1
          3      > JMPZ                                                     ~2, ->9
   38     4    >   FETCH_OBJ_R                                      ~4      'provider'
          5        INIT_USER_CALL                                0          'call_user_func', ~4
          6        DO_FCALL                                      0  $5      
          7        ASSIGN_OBJ                                               'connection'
          8        OP_DATA                                                  $5
   40     9    >   FETCH_CLASS                                   0  $6      !0
         10        NEW                                              $7      $6
         11        CHECK_FUNC_ARG                                           
         12        FETCH_OBJ_FUNC_ARG                               $8      'connection'
         13        SEND_FUNC_ARG                                            $8
         14        DO_FCALL                                      0          
         15      > RETURN                                                   $7
   41    16*     > RETURN                                                   null

End of function create

End of class StructureFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.97 ms | 1399 KiB | 13 Q