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(); var_dump($singy, $singy2); $derp = Closure::bind(function () {$fake = new Singleton(); $fake->id='hacked'; return $fake;}, $singy2, get_class($singy2)); $singy2 = $derp(); $singy2->doAction(); $singy->doAction(); var_dump($singy, $singy2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0RTnm
function name:  (null)
number of ops:  32
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_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   27    12        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0RTnm%3A27%240'
         14        SEND_VAL                                                 ~9
         15        SEND_VAR                                                 !1
         16        GET_CLASS                                        ~10     !1
         17        SEND_VAL                                                 ~10
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !2, $11
   28    20        INIT_DYNAMIC_CALL                                        !2
         21        DO_FCALL                                      0  $13     
         22        ASSIGN                                                   !1, $13
   29    23        INIT_METHOD_CALL                                         !1, 'doAction'
         24        DO_FCALL                                      0          
   30    25        INIT_METHOD_CALL                                         !0, 'doAction'
         26        DO_FCALL                                      0          
   31    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !0
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F0RTnm%3A27%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0RTnm
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $fake
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $1      'Singleton'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
          3        ASSIGN_OBJ                                               !0, 'id'
          4        OP_DATA                                                  'hacked'
          5      > RETURN                                                   !0
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0RTnm%3A27%240

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