3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Aareon_Abstract { public static $instance; public static function getInstance() { if (self::$instance === null) { self::$instance = new static(); } return self::$instance; } } class Aareon_MaterializedView extends Aareon_Abstract { public static $instance; } class Sample extends Aareon_Abstract { } echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; echo get_class(Aareon_MaterializedView::getInstance()) . PHP_EOL; //As you can see, a new B is instantiated here, because B::$instance is a priority over A::$instance. echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; A::$instance = null; echo PHP_EOL; echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL; echo get_class(Sample::getInstance()) . PHP_EOL; //But here, there is no C::$instance, so let's check the A::$instance which is not empty. echo get_class(Aareon_Abstract::getInstance()) . PHP_EOL;
based on sGQGS
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HfZlr
function name:  (null)
number of ops:  39
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  15     1        NOP                                                      
         2        NOP                                                      
  20     3        NOP                                                      
         4        NOP                                                      
  24     5        INIT_STATIC_METHOD_CALL                                  'Aareon_Abstract', 'getInstance'
         6        DO_FCALL                                      0  $5      
         7        GET_CLASS                                        ~6      $5
         8        CONCAT                                           ~7      ~6, '%0A'
         9        ECHO                                                     ~7
  25    10        INIT_STATIC_METHOD_CALL                                  'Aareon_MaterializedView', 'getInstance'
        11        DO_FCALL                                      0  $8      
        12        GET_CLASS                                        ~9      $8
        13        CONCAT                                           ~10     ~9, '%0A'
        14        ECHO                                                     ~10
  26    15        INIT_STATIC_METHOD_CALL                                  'Aareon_Abstract', 'getInstance'
        16        DO_FCALL                                      0  $11     
        17        GET_CLASS                                        ~12     $11
        18        CONCAT                                           ~13     ~12, '%0A'
        19        ECHO                                                     ~13
  28    20        FETCH_STATIC_PROP_W          global              $14     'instance'
        21        ASSIGN                                                   $14, null
  29    22        ECHO                                                     '%0A'
  31    23        INIT_STATIC_METHOD_CALL                                  'Aareon_Abstract', 'getInstance'
        24        DO_FCALL                                      0  $16     
        25        GET_CLASS                                        ~17     $16
        26        CONCAT                                           ~18     ~17, '%0A'
        27        ECHO                                                     ~18
  32    28        INIT_STATIC_METHOD_CALL                                  'Sample', 'getInstance'
        29        DO_FCALL                                      0  $19     
        30        GET_CLASS                                        ~20     $19
        31        CONCAT                                           ~21     ~20, '%0A'
        32        ECHO                                                     ~21
  33    33        INIT_STATIC_METHOD_CALL                                  'Aareon_Abstract', 'getInstance'
        34        DO_FCALL                                      0  $22     
        35        GET_CLASS                                        ~23     $22
        36        CONCAT                                           ~24     ~23, '%0A'
        37        ECHO                                                     ~24
        38      > RETURN                                                   1

Class Aareon_Abstract:
Function getinstance:
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/HfZlr
function name:  getInstance
number of ops:  10
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   8     0  E >   FETCH_STATIC_PROP_R          global              $0      'instance'
         1        IS_IDENTICAL                                     ~1      $0, null
         2      > JMPZ                                                     ~1, ->7
   9     3    >   NEW                                              $3      :27
         4        DO_FCALL                                      0          
         5        FETCH_STATIC_PROP_W          global              $2      'instance'
         6        ASSIGN                                                   $2, $3
  11     7    >   FETCH_STATIC_PROP_R          global              $6      'instance'
         8      > RETURN                                                   $6
  12     9*     > RETURN                                                   null

End of function getinstance

End of class Aareon_Abstract.

Class Aareon_MaterializedView:
Function getinstance:
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/HfZlr
function name:  getInstance
number of ops:  10
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   8     0  E >   FETCH_STATIC_PROP_R          global              $0      'instance'
         1        IS_IDENTICAL                                     ~1      $0, null
         2      > JMPZ                                                     ~1, ->7
   9     3    >   NEW                                              $3      :27
         4        DO_FCALL                                      0          
         5        FETCH_STATIC_PROP_W          global              $2      'instance'
         6        ASSIGN                                                   $2, $3
  11     7    >   FETCH_STATIC_PROP_R          global              $6      'instance'
         8      > RETURN                                                   $6
  12     9*     > RETURN                                                   null

End of function getinstance

End of class Aareon_MaterializedView.

Class Sample:
Function getinstance:
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/HfZlr
function name:  getInstance
number of ops:  10
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   8     0  E >   FETCH_STATIC_PROP_R          global              $0      'instance'
         1        IS_IDENTICAL                                     ~1      $0, null
         2      > JMPZ                                                     ~1, ->7
   9     3    >   NEW                                              $3      :27
         4        DO_FCALL                                      0          
         5        FETCH_STATIC_PROP_W          global              $2      'instance'
         6        ASSIGN                                                   $2, $3
  11     7    >   FETCH_STATIC_PROP_R          global              $6      'instance'
         8      > RETURN                                                   $6
  12     9*     > RETURN                                                   null

End of function getinstance

End of class Sample.

Generated using Vulcan Logic Dumper, using php 7.3.0