3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { private static $instanciated = false; public function __construct() { if (self::$instanciated === true) { throw new RuntimeException('Could not instanciate class'); } self::$instanciated = true; } private $var; public function get(): int { return $this->var; } public function set(int $value) { $this->var = $value; } } class Factory { private $instance = null; public function getInstance() { echo "getInstance()\n"; if ($this->instance === null) { $this->instance = new Singleton(); } return $this->instance; } } $factory = new Factory(); $o = $factory->getInstance(); $o->set(5); $factory2 = new Factory(); $o2 = $factory->getInstance(); var_dump($o2->get());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n4jEW
function name:  (null)
number of ops:  21
compiled vars:  !0 = $factory, !1 = $o, !2 = $factory2, !3 = $o2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   NEW                                              $4      'Factory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   40     3        INIT_METHOD_CALL                                         !0, 'getInstance'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !1, $7
   41     6        INIT_METHOD_CALL                                         !1, 'set'
          7        SEND_VAL_EX                                              5
          8        DO_FCALL                                      0          
   43     9        NEW                                              $10     'Factory'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   44    12        INIT_METHOD_CALL                                         !0, 'getInstance'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   45    15        INIT_FCALL                                               'var_dump'
         16        INIT_METHOD_CALL                                         !3, 'get'
         17        DO_FCALL                                      0  $15     
         18        SEND_VAR                                                 $15
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Class Singleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n4jEW
function name:  __construct
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instanciated'
          1        TYPE_CHECK                                    8          ~0
          2      > JMPZ                                                     ~1, ->7
    9     3    >   NEW                                              $2      'RuntimeException'
          4        SEND_VAL_EX                                              'Could+not+instanciate+class'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   11     7    >   ASSIGN_STATIC_PROP                                       'instanciated'
          8        OP_DATA                                                  <true>
   12     9      > RETURN                                                   null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n4jEW
function name:  get
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'var'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   18     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n4jEW
function name:  set
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ASSIGN_OBJ                                               'var'
          2        OP_DATA                                                  !0
   22     3      > RETURN                                                   null

End of function set

End of class Singleton.

Class Factory:
Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/n4jEW
function name:  getInstance
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'getInstance%28%29%0A'
   32     1        FETCH_OBJ_R                                      ~0      'instance'
          2        TYPE_CHECK                                    2          ~0
          3      > JMPZ                                                     ~1, ->8
   33     4    >   NEW                                              $3      'Singleton'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'instance'
          7        OP_DATA                                                  $3
   35     8    >   FETCH_OBJ_R                                      ~5      'instance'
          9      > RETURN                                                   ~5
   36    10*     > RETURN                                                   null

End of function getinstance

End of class Factory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.4 ms | 1400 KiB | 15 Q