3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { private static $instance; private function __construct() {} private function __clone() {} private function __wakeup() {} public static function getInstance() { if (empty(static::$instanse)) { return new static(); } else { return static::$instance; } } } class Foo { use Singleton; private $bar = 2; public function incBar() { $this->bar++; } public function getBar() { return $this->bar."<br/>"; } } $foo = new Foo(); $foo = Foo::getInstance(); echo $foo->getBar(); $foo->incBar(); echo $foo->getBar();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
function name:  (null)
number of ops:  16
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   DECLARE_CLASS                                            'foo'
   38     1        NEW                                              $1      'Foo'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   39     4        INIT_STATIC_METHOD_CALL                                  'Foo', 'getInstance'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !0, $4
   41     7        INIT_METHOD_CALL                                         !0, 'getBar'
          8        DO_FCALL                                      0  $6      
          9        ECHO                                                     $6
   42    10        INIT_METHOD_CALL                                         !0, 'incBar'
         11        DO_FCALL                                      0          
   43    12        INIT_METHOD_CALL                                         !0, 'getBar'
         13        DO_FCALL                                      0  $8      
         14        ECHO                                                     $8
         15      > RETURN                                                   1

Class Singleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
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/jEPeD
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 __wakeup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
function name:  __wakeup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     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 = 2, Position 2 = 6
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
function name:  getInstance
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ISSET_ISEMPTY_STATIC_PROP                                'instanse'
          1      > JMPZ                                                     ~0, ->6
   14     2    >   NEW                          static              $1      
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
          5*       JMP                                                      ->8
   16     6    >   FETCH_STATIC_PROP_R          unknown             ~3      'instance'
          7      > RETURN                                                   ~3
   18     8*     > RETURN                                                   null

End of function getinstance

End of class Singleton.

Class Foo:
Function incbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
function name:  incBar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   PRE_INC_OBJ                                              'bar'
   30     1      > RETURN                                                   null

End of function incbar

Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jEPeD
function name:  getBar
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1        CONCAT                                           ~1      ~0, '%3Cbr%2F%3E'
          2      > RETURN                                                   ~1
   35     3*     > RETURN                                                   null

End of function getbar

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.02 ms | 1399 KiB | 13 Q