3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { private static $instance = null; final private function __construct() {} final private function __clone() {} public static function getInstance() { if (!self::$instance) { self::$instance = new self; } return self::$instance; } } $oneInstance = Singleton::getInstance(); $isCloneable = (new ReflectionClass('Singleton'))->isCloneable(); $creator = function () { return clone $this; }; $secondInstance = $creator->bindTo($oneInstance, 'Singleton')->__invoke(); var_dump($isCloneable, $oneInstance, $secondInstance);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WpGFH
function name:  (null)
number of ops:  24
compiled vars:  !0 = $oneInstance, !1 = $isCloneable, !2 = $creator, !3 = $secondInstance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          1        DO_FCALL                                      0  $4      
          2        ASSIGN                                                   !0, $4
   20     3        NEW                                              $6      'ReflectionClass'
          4        SEND_VAL_EX                                              'Singleton'
          5        DO_FCALL                                      0          
          6        INIT_METHOD_CALL                                         $6, 'isCloneable'
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !1, $8
   21     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWpGFH%3A21%240'
         10        ASSIGN                                                   !2, ~10
   24    11        INIT_METHOD_CALL                                         !2, 'bindTo'
         12        SEND_VAR_EX                                              !0
         13        SEND_VAL_EX                                              'Singleton'
         14        DO_FCALL                                      0  $12     
         15        INIT_METHOD_CALL                                         $12, '__invoke'
         16        DO_FCALL                                      0  $13     
         17        ASSIGN                                                   !3, $13
   25    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !1
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FWpGFH%3A21%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WpGFH
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_THIS                                       ~0      
          1        CLONE                                            ~1      ~0
          2      > RETURN                                                   ~1
   23     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWpGFH%3A21%240

Class Singleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WpGFH
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     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/WpGFH
function name:  __clone
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E > > RETURN                                                   null

End of function __clone

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/WpGFH
function name:  getInstance
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instance'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->7
   13     3    >   NEW                          self                $3      
          4        DO_FCALL                                      0          
          5        ASSIGN_STATIC_PROP                                       'instance'
          6        OP_DATA                                                  $3
   15     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'instance'
          8      > RETURN                                                   ~5
   16     9*     > RETURN                                                   null

End of function getinstance

End of class Singleton.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.74 ms | 1400 KiB | 15 Q