3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { /** * @var Singleton The reference to *Singleton* instance of this class */ protected static $instance; /** * Returns the *Singleton* instance of this class. * * @return Singleton The *Singleton* instance. */ public static function getInstance() { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } /** * Protected constructor to prevent creating a new instance of the * *Singleton* via the `new` operator from outside of this class. */ protected function __construct() { } /** * Private clone method to prevent cloning of the instance of the * *Singleton* instance. * * @return void */ private function __clone() { } /** * Private unserialize method to prevent unserializing of the *Singleton* * instance. * * @return void */ private function __wakeup() { } } class SingletonChild extends Singleton { } $obj = Singleton::getInstance(); var_dump($obj === Singleton::getInstance()); // bool(true) $anotherObj = SingletonChild::getInstance(); var_dump($anotherObj === Singleton::getInstance()); // bool(false) var_dump($anotherObj === SingletonChild::getInstance()); // bool(true)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YSPL3
function name:  (null)
number of ops:  25
compiled vars:  !0 = $obj, !1 = $anotherObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   58     3        INIT_FCALL                                               'var_dump'
          4        INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          5        DO_FCALL                                      0  $4      
          6        IS_IDENTICAL                                     ~5      !0, $4
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                                 
   60     9        INIT_STATIC_METHOD_CALL                                  'SingletonChild', 'getInstance'
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !1, $7
   61    12        INIT_FCALL                                               'var_dump'
         13        INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
         14        DO_FCALL                                      0  $9      
         15        IS_IDENTICAL                                     ~10     !1, $9
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                                 
   63    18        INIT_FCALL                                               'var_dump'
         19        INIT_STATIC_METHOD_CALL                                  'SingletonChild', 'getInstance'
         20        DO_FCALL                                      0  $12     
         21        IS_IDENTICAL                                     ~13     !1, $12
         22        SEND_VAL                                                 ~13
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Class Singleton:
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/YSPL3
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   18     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   21     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   22     9*     > RETURN                                                   null

End of function getinstance

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

End of function __construct

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

End of function __clone

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

End of function __wakeup

End of class Singleton.

Class SingletonChild:
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/YSPL3
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->7
   18     3    >   NEW                          static              $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   21     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   22     9*     > RETURN                                                   null

End of function getinstance

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

End of function __construct

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

End of function __clone

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

End of function __wakeup

End of class SingletonChild.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.58 ms | 1404 KiB | 15 Q