3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton{ private static $instance; private function __construct(){} private function __clone() {} public static function instance() { if (is_null(self::$instance)){ self::$instance = new static; } return self::$instance; } } $obj1 = Singleton::instance(); $obj2 = Singleton::instance(); var_dump(spl_object_hash($obj1), spl_object_hash($obj2)); $closure = function(){ return clone self::$instance; }; $cloner = $closure->bindTo($obj1, 'Singleton'); $obj3 = $cloner(); var_dump(spl_object_hash($obj3));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqARU
function name:  (null)
number of ops:  33
compiled vars:  !0 = $obj1, !1 = $obj2, !2 = $closure, !3 = $cloner, !4 = $obj3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_STATIC_METHOD_CALL                                  'Singleton', 'instance'
          1        DO_FCALL                                      0  $5      
          2        ASSIGN                                                   !0, $5
   31     3        INIT_STATIC_METHOD_CALL                                  'Singleton', 'instance'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !1, $7
   33     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'spl_object_hash'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10        SEND_VAR                                                 $9
         11        INIT_FCALL                                               'spl_object_hash'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $10     
         14        SEND_VAR                                                 $10
         15        DO_ICALL                                                 
   37    16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaqARU%3A37%240'
         17        ASSIGN                                                   !2, ~12
   42    18        INIT_METHOD_CALL                                         !2, 'bindTo'
         19        SEND_VAR_EX                                              !0
         20        SEND_VAL_EX                                              'Singleton'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !3, $14
   44    23        INIT_DYNAMIC_CALL                                        !3
         24        DO_FCALL                                      0  $16     
         25        ASSIGN                                                   !4, $16
   46    26        INIT_FCALL                                               'var_dump'
         27        INIT_FCALL                                               'spl_object_hash'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $18     
         30        SEND_VAR                                                 $18
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FaqARU%3A37%240

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

End of function __clone

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

End of function instance

End of class Singleton.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.42 ms | 1400 KiB | 17 Q