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 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 = 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/AJmhE
function name:  (null)
number of ops:  13
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   DECLARE_CLASS                                            'foo'
   38     1        INIT_STATIC_METHOD_CALL                                  'Foo', 'getInstance'
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   40     4        INIT_METHOD_CALL                                         !0, 'getBar'
          5        DO_FCALL                                      0  $3      
          6        ECHO                                                     $3
   41     7        INIT_METHOD_CALL                                         !0, 'incBar'
          8        DO_FCALL                                      0          
   42     9        INIT_METHOD_CALL                                         !0, 'getBar'
         10        DO_FCALL                                      0  $5      
         11        ECHO                                                     $5
         12      > RETURN                                                   1

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