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($isCloneable = (new ReflectionClass('Singleton'))->isCloneable()); $creator = function () { echo "Cloneable inside:", var_dump($isCloneable = (new ReflectionClass('Singleton'))->isCloneable()); return clone $this; }; $secondInstance = $creator->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/R4gYL
function name:  (null)
number of ops:  28
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        ECHO                                                     'Cloneable+outside%3A'
          4        INIT_FCALL                                               'var_dump'
          5        NEW                                              $6      'ReflectionClass'
          6        SEND_VAL_EX                                              'Singleton'
          7        DO_FCALL                                      0          
          8        INIT_METHOD_CALL                                         $6, 'isCloneable'
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                           ~9      !1, $8
         11        SEND_VAL                                                 ~9
         12        DO_ICALL                                         $10     
         13        ECHO                                                     $10
   22    14        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FR4gYL%3A22%240'
         15        ASSIGN                                                   !2, ~11
   27    16        INIT_METHOD_CALL                                         !2, 'bindTo'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAL_EX                                              'Singleton'
         19        DO_FCALL                                      0  $13     
         20        INIT_METHOD_CALL                                         $13, '__invoke'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !3, $14
   28    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !0
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FR4gYL%3A22%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R4gYL
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $isCloneable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ECHO                                                     'Cloneable+inside%3A'
          1        INIT_FCALL                                               'var_dump'
          2        NEW                                              $1      'ReflectionClass'
          3        SEND_VAL_EX                                              'Singleton'
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $1, 'isCloneable'
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                           ~4      !0, $3
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        ECHO                                                     $5
   24    11        FETCH_THIS                                       ~6      
         12        CLONE                                            ~7      ~6
         13      > RETURN                                                   ~7
   25    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FR4gYL%3A22%240

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