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(); echo "Cloneable outside:", var_dump((new ReflectionClass('Singleton'))->isCloneable()); $cloner = function () { return clone $this; }; $secondInstance = $cloner->bindTo($oneInstance, 'Singleton')->__invoke(); var_dump($oneInstance, $secondInstance);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v8SIO
function name:  (null)
number of ops:  27
compiled vars:  !0 = $oneInstance, !1 = $cloner, !2 = $secondInstance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   20     3        ECHO                                                     'Cloneable+outside%3A'
          4        INIT_FCALL                                               'var_dump'
          5        NEW                                              $5      'ReflectionClass'
          6        SEND_VAL_EX                                              'Singleton'
          7        DO_FCALL                                      0          
          8        INIT_METHOD_CALL                                         $5, 'isCloneable'
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                         $8      
         12        ECHO                                                     $8
   22    13        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
         14        ASSIGN                                                   !1, ~9
   26    15        INIT_METHOD_CALL                                         !1, 'bindTo'
         16        SEND_VAR_EX                                              !0
         17        SEND_VAL_EX                                              'Singleton'
         18        DO_FCALL                                      0  $11     
         19        INIT_METHOD_CALL                                         $11, '__invoke'
         20        DO_FCALL                                      0  $12     
         21        ASSIGN                                                   !2, $12
   27    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !0
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
         26      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v8SIO
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_THIS                                       ~0      
          1        CLONE                                            ~1      ~0
          2      > RETURN                                                   ~1
   24     3*     > RETURN                                                   null

End of Dynamic Function 0

Class Singleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v8SIO
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/v8SIO
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/v8SIO
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:
187.13 ms | 1456 KiB | 14 Q