3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$in2 = Closure::bind(function () {$this->ruler = 'jesus';}, $inst, get_class($inst)); class Singleton { protected static $instance; // object instance private function __construct(){ /* ... @return Singleton */ } // Защищаем от создания через new Singleton private function __clone() { /* ... @return Singleton */ } // Защищаем от создания через клонирование private function __wakeup() { /* ... @return Singleton */ } // Защищаем от создания через unserialize public static function getInstance() { // Возвращает единственный экземпляр класса. @return Singleton if ( !isset(self::$instance) ) { $class = __CLASS__; self::$instance = new $class(); self::$instance->id = mt_rand(1,1000); } return self::$instance; } public function doAction() { echo $this->id; } } $singy = Singleton::getInstance(); $singy->doAction(); $singy2 = Singleton::getInstance(); $derp = Closure::bind(function () {return new Singleton();}, $singy2, get_class($singy2)); $singy2 = $derp(); $singy2->doAction(); $singy->doAction();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uZQjP
function name:  (null)
number of ops:  24
compiled vars:  !0 = $singy, !1 = $singy2, !2 = $derp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   24     3        INIT_METHOD_CALL                                         !0, 'doAction'
          4        DO_FCALL                                      0          
   25     5        INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   26     8        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FuZQjP%3A26%240'
         10        SEND_VAL                                                 ~8
         11        SEND_VAR                                                 !1
         12        GET_CLASS                                        ~9      !1
         13        SEND_VAL                                                 ~9
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !2, $10
   27    16        INIT_DYNAMIC_CALL                                        !2
         17        DO_FCALL                                      0  $12     
         18        ASSIGN                                                   !1, $12
   28    19        INIT_METHOD_CALL                                         !1, 'doAction'
         20        DO_FCALL                                      0          
   29    21        INIT_METHOD_CALL                                         !0, 'doAction'
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FuZQjP%3A26%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uZQjP
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $0      'Singleton'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FuZQjP%3A26%240

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

End of function __wakeup

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/uZQjP
function name:  getInstance
number of ops:  19
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ISSET_ISEMPTY_STATIC_PROP                        ~1      'instance'
          1        BOOL_NOT                                         ~2      ~1
          2      > JMPZ                                                     ~2, ->16
   13     3    >   ASSIGN                                                   !0, 'Singleton'
   14     4        FETCH_CLASS                                   0  $5      !0
          5        NEW                                              $6      $5
          6        DO_FCALL                                      0          
          7        ASSIGN_STATIC_PROP                                       'instance'
          8        OP_DATA                                                  $6
   15     9        INIT_FCALL                                               'mt_rand'
         10        SEND_VAL                                                 1
         11        SEND_VAL                                                 1000
         12        DO_ICALL                                         $10     
         13        FETCH_STATIC_PROP_W          unknown             $8      'instance'
         14        ASSIGN_OBJ                                               $8, 'id'
         15        OP_DATA                                                  $10
   17    16    >   FETCH_STATIC_PROP_R          unknown             ~11     'instance'
         17      > RETURN                                                   ~11
   18    18*     > RETURN                                                   null

End of function getinstance

Function doaction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uZQjP
function name:  doAction
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                      ~0      'id'
          1        ECHO                                                     ~0
          2      > RETURN                                                   null

End of function doaction

End of class Singleton.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.61 ms | 1400 KiB | 15 Q