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::get_instance('Foo'); $one = Loader::get_instance('One'); $two = Loader::get_instance('Two'); $foo2 = Loader::get_instance('Foo'); $foo3 = Loader::get_instance('Foo'); Loader::debug();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3u1ve
function name:  (null)
number of ops:  26
compiled vars:  !0 = $foo, !1 = $one, !2 = $two, !3 = $foo2, !4 = $foo3
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', 'get_instance'
          4        SEND_VAL                                                 'Foo'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !0, $5
   20     7        INIT_STATIC_METHOD_CALL                                  'Loader', 'get_instance'
          8        SEND_VAL                                                 'One'
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !1, $7
   21    11        INIT_STATIC_METHOD_CALL                                  'Loader', 'get_instance'
         12        SEND_VAL                                                 'Two'
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !2, $9
   22    15        INIT_STATIC_METHOD_CALL                                  'Loader', 'get_instance'
         16        SEND_VAL                                                 'Foo'
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !3, $11
   23    19        INIT_STATIC_METHOD_CALL                                  'Loader', 'get_instance'
         20        SEND_VAL                                                 'Foo'
         21        DO_FCALL                                      0  $13     
         22        ASSIGN                                                   !4, $13
   24    23        INIT_STATIC_METHOD_CALL                                  'Loader', 'debug'
         24        DO_FCALL                                      0          
         25      > 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/3u1ve
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/3u1ve
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/3u1ve
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/3u1ve
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/3u1ve
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:
153.73 ms | 1400 KiB | 15 Q