3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public static $instance; public static function getInstance() { if (self::$instance === null) { self::$instance = new static(); } return static::$instance; } } class B extends A { public static $instance; } class C extends A { } echo get_class(A::getInstance()) . PHP_EOL; echo var_dump(B::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(A::getInstance()) . PHP_EOL; A::$instance = null; echo PHP_EOL; echo get_class(A::getInstance()) . PHP_EOL; echo get_class(C::getInstance()) . PHP_EOL; //But here, there is no C::$instance, so let's check the A::$instance which is not empty. echo get_class(A::getInstance()) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7EonG
function name:  (null)
number of ops:  36
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
          1        DO_FCALL                                      0  $0      
          2        GET_CLASS                                        ~1      $0
          3        CONCAT                                           ~2      ~1, '%0A'
          4        ECHO                                                     ~2
   25     5        INIT_FCALL                                               'var_dump'
          6        INIT_STATIC_METHOD_CALL                                  'B', 'getInstance'
          7        DO_FCALL                                      0  $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      $4, '%0A'
         11        ECHO                                                     ~5
   26    12        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         13        DO_FCALL                                      0  $6      
         14        GET_CLASS                                        ~7      $6
         15        CONCAT                                           ~8      ~7, '%0A'
         16        ECHO                                                     ~8
   28    17        ASSIGN_STATIC_PROP                                       'instance', 'A'
         18        OP_DATA                                                  null
   29    19        ECHO                                                     '%0A'
   31    20        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         21        DO_FCALL                                      0  $10     
         22        GET_CLASS                                        ~11     $10
         23        CONCAT                                           ~12     ~11, '%0A'
         24        ECHO                                                     ~12
   32    25        INIT_STATIC_METHOD_CALL                                  'C', 'getInstance'
         26        DO_FCALL                                      0  $13     
         27        GET_CLASS                                        ~14     $13
         28        CONCAT                                           ~15     ~14, '%0A'
         29        ECHO                                                     ~15
   33    30        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         31        DO_FCALL                                      0  $16     
         32        GET_CLASS                                        ~17     $16
         33        CONCAT                                           ~18     ~17, '%0A'
         34        ECHO                                                     ~18
         35      > RETURN                                                   1

Class A:
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/7EonG
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          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
    9     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   11     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   12     9*     > RETURN                                                   null

End of function getinstance

End of class A.

Class B:
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/7EonG
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          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
    9     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   11     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   12     9*     > RETURN                                                   null

End of function getinstance

End of class B.

Class C:
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/7EonG
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          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
    9     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   11     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   12     9*     > RETURN                                                   null

End of function getinstance

End of class C.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
271.62 ms | 948 KiB | 16 Q