3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Loader { private static $instances; public static function get_instance($class) { if(!isset(self::$instances[$class])) { self::$instances[$class] = new $class(); } return self::$instances[$class]; } public static function debug() { print_r(self::$instances); } } class One{ public function __toString() { return 'One'; } } class Two{ public function __toString() { return 'Two'; } } class Foo{ public function __toString() { return 'Foo'; } } $foo = Loader::instance('Foo'); $one = Loader::instance('One'); $two = Loader::instance('Two'); Loader::debug();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNQSq
function name:  (null)
number of ops:  18
compiled vars:  !0 = $foo, !1 = $one, !2 = $two
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_CLASS                                            'one'
   16     1        DECLARE_CLASS                                            'two'
   17     2        DECLARE_CLASS                                            'foo'
   19     3        INIT_STATIC_METHOD_CALL                                  'Loader', 'instance'
          4        SEND_VAL_EX                                              'Foo'
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !0, $3
   20     7        INIT_STATIC_METHOD_CALL                                  'Loader', 'instance'
          8        SEND_VAL_EX                                              'One'
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   21    11        INIT_STATIC_METHOD_CALL                                  'Loader', 'instance'
         12        SEND_VAL_EX                                              'Two'
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !2, $7
   22    15        INIT_STATIC_METHOD_CALL                                  'Loader', 'debug'
         16        DO_FCALL                                      0          
         17      > RETURN                                                   1

Class Loader:
Function get_instance:
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 = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/NNQSq
function name:  get_instance
number of ops:  15
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        FETCH_STATIC_PROP_IS                             ~1      'instances'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->11
    7     5    >   FETCH_CLASS                                   0  $6      !0
          6        NEW                                              $7      $6
          7        DO_FCALL                                      0          
          8        FETCH_STATIC_PROP_W          unknown             $4      'instances'
          9        ASSIGN_DIM                                               $4, !0
         10        OP_DATA                                                  $7
   10    11    >   FETCH_STATIC_PROP_R          unknown             ~9      'instances'
         12        FETCH_DIM_R                                      ~10     ~9, !0
         13      > RETURN                                                   ~10
   11    14*     > RETURN                                                   null

End of function get_instance

Function debug:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNQSq
function name:  debug
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'print_r'
          1        FETCH_STATIC_PROP_R          global lock         ~0      'instances'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                                 
          4      > RETURN                                                   null

End of function debug

End of class Loader.

Class One:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNQSq
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E > > RETURN                                                   'One'
          1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class One.

Class Two:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNQSq
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E > > RETURN                                                   'Two'
          1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class Two.

Class Foo:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNQSq
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E > > RETURN                                                   'Foo'
          1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.28 ms | 1392 KiB | 15 Q