3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Foo { private static $instances = array(); private function __construct() { } public static function getInstance() { return isset(static::$instances[$className = get_called_class()]) ? static::$instances[$className] : static::$instances[$className] = new static(); } } final class Bar extends Foo { } final class Baz extends Foo { } $bar = Bar::getInstance(); echo get_class($bar), "\n"; $baz = Baz::getInstance(); echo get_class($baz), "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/scXLD
function name:  (null)
number of ops:  13
compiled vars:  !0 = $bar, !1 = $baz
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_STATIC_METHOD_CALL                                  'Bar', 'getInstance'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   19     3        GET_CLASS                                        ~4      !0
          4        ECHO                                                     ~4
          5        ECHO                                                     '%0A'
   21     6        INIT_STATIC_METHOD_CALL                                  'Baz', 'getInstance'
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
   22     9        GET_CLASS                                        ~7      !1
         10        ECHO                                                     ~7
         11        ECHO                                                     '%0A'
         12      > RETURN                                                   1

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

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/scXLD
function name:  getInstance
number of ops:  17
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   GET_CALLED_CLASS                                 ~2      
          1        ASSIGN                                           ~3      !0, ~2
          2        FETCH_STATIC_PROP_IS                             ~1      'instances'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          4      > JMPZ                                                     ~4, ->9
          5    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          6        FETCH_DIM_R                                      ~6      ~5, !0
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->15
          9    >   NEW                          static              $10     
         10        DO_FCALL                                      0          
         11        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         12        ASSIGN_DIM                                       ~9      $8, !0
         13        OP_DATA                                                  $10
         14        QM_ASSIGN                                        ~7      ~9
         15    > > RETURN                                                   ~7
    9    16*     > RETURN                                                   null

End of function getinstance

End of class Foo.

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

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/scXLD
function name:  getInstance
number of ops:  17
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   GET_CALLED_CLASS                                 ~2      
          1        ASSIGN                                           ~3      !0, ~2
          2        FETCH_STATIC_PROP_IS                             ~1      'instances'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          4      > JMPZ                                                     ~4, ->9
          5    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          6        FETCH_DIM_R                                      ~6      ~5, !0
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->15
          9    >   NEW                          static              $10     
         10        DO_FCALL                                      0          
         11        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         12        ASSIGN_DIM                                       ~9      $8, !0
         13        OP_DATA                                                  $10
         14        QM_ASSIGN                                        ~7      ~9
         15    > > RETURN                                                   ~7
    9    16*     > RETURN                                                   null

End of function getinstance

End of class Bar.

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

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/scXLD
function name:  getInstance
number of ops:  17
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   GET_CALLED_CLASS                                 ~2      
          1        ASSIGN                                           ~3      !0, ~2
          2        FETCH_STATIC_PROP_IS                             ~1      'instances'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          4      > JMPZ                                                     ~4, ->9
          5    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          6        FETCH_DIM_R                                      ~6      ~5, !0
          7        QM_ASSIGN                                        ~7      ~6
          8      > JMP                                                      ->15
          9    >   NEW                          static              $10     
         10        DO_FCALL                                      0          
         11        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         12        ASSIGN_DIM                                       ~9      $8, !0
         13        OP_DATA                                                  $10
         14        QM_ASSIGN                                        ~7      ~9
         15    > > RETURN                                                   ~7
    9    16*     > RETURN                                                   null

End of function getinstance

End of class Baz.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.49 ms | 1403 KiB | 13 Q