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 get_class(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/qZZWP
function name:  (null)
number of ops:  34
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_STATIC_METHOD_CALL                                  'B', 'getInstance'
          6        DO_FCALL                                      0  $3      
          7        GET_CLASS                                        ~4      $3
          8        CONCAT                                           ~5      ~4, '%0A'
          9        ECHO                                                     ~5
   26    10        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         11        DO_FCALL                                      0  $6      
         12        GET_CLASS                                        ~7      $6
         13        CONCAT                                           ~8      ~7, '%0A'
         14        ECHO                                                     ~8
   28    15        ASSIGN_STATIC_PROP                                       'instance', 'A'
         16        OP_DATA                                                  null
   29    17        ECHO                                                     '%0A'
   31    18        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         19        DO_FCALL                                      0  $10     
         20        GET_CLASS                                        ~11     $10
         21        CONCAT                                           ~12     ~11, '%0A'
         22        ECHO                                                     ~12
   32    23        INIT_STATIC_METHOD_CALL                                  'C', 'getInstance'
         24        DO_FCALL                                      0  $13     
         25        GET_CLASS                                        ~14     $13
         26        CONCAT                                           ~15     ~14, '%0A'
         27        ECHO                                                     ~15
   33    28        INIT_STATIC_METHOD_CALL                                  'A', 'getInstance'
         29        DO_FCALL                                      0  $16     
         30        GET_CLASS                                        ~17     $16
         31        CONCAT                                           ~18     ~17, '%0A'
         32        ECHO                                                     ~18
         33      > 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/qZZWP
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/qZZWP
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/qZZWP
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:
151.09 ms | 1399 KiB | 13 Q