3v4l.org

run code in 300+ PHP versions simultaneously
<?php class hell { private $ruler = 'devil'; function cry(){ echo $this->ruler; } } $inst = new hell(); $inst->cry(); $in2 = Closure::bind(function () {$this->ruler = 'jesus';}, $inst, get_class($inst)); $in2(); $inst->cry(); 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; } } Singleton::getInstance()->doAction(); // Применение $singy = Singleton::getInstance();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/shaCg
function name:  (null)
number of ops:  25
compiled vars:  !0 = $inst, !1 = $in2, !2 = $singy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $3      'hell'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   13     3        INIT_METHOD_CALL                                         !0, 'cry'
          4        DO_FCALL                                      0          
   15     5        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FshaCg%3A15%240'
          7        SEND_VAL                                                 ~7
          8        SEND_VAR                                                 !0
          9        GET_CLASS                                        ~8      !0
         10        SEND_VAL                                                 ~8
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !1, $9
   16    13        INIT_DYNAMIC_CALL                                        !1
         14        DO_FCALL                                      0          
   17    15        INIT_METHOD_CALL                                         !0, 'cry'
         16        DO_FCALL                                      0          
   34    17        INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
         18        DO_FCALL                                      0  $13     
         19        INIT_METHOD_CALL                                         $13, 'doAction'
         20        DO_FCALL                                      0          
   36    21        INIT_STATIC_METHOD_CALL                                  'Singleton', 'getInstance'
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !2, $15
         24      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FshaCg%3A15%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/shaCg
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_THIS                                       $0      
          1        ASSIGN_OBJ                                               $0, 'ruler'
          2        OP_DATA                                                  'jesus'
          3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FshaCg%3A15%240

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

End of function cry

End of class hell.

Class Singleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/shaCg
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     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/shaCg
function name:  __clone
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     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/shaCg
function name:  __wakeup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     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/shaCg
function name:  getInstance
number of ops:  19
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ISSET_ISEMPTY_STATIC_PROP                        ~1      'instance'
          1        BOOL_NOT                                         ~2      ~1
          2      > JMPZ                                                     ~2, ->16
   26     3    >   ASSIGN                                                   !0, 'Singleton'
   27     4        FETCH_CLASS                                   0  $5      !0
          5        NEW                                              $6      $5
          6        DO_FCALL                                      0          
          7        ASSIGN_STATIC_PROP                                       'instance'
          8        OP_DATA                                                  $6
   28     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
   30    16    >   FETCH_STATIC_PROP_R          unknown             ~11     'instance'
         17      > RETURN                                                   ~11
   31    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/shaCg
function name:  doAction
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     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:
149.34 ms | 1404 KiB | 15 Q