3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Factory { private $instance = null; public function getInstance() { if ($this->instance === null) { $this->instance = new class() { private static $instanciated = false; public function __construct() { if (self::$instanciated) { 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; } }; } 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/HgOW9
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
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $4      'Factory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   37     3        INIT_METHOD_CALL                                         !0, 'getInstance'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !1, $7
   38     6        INIT_METHOD_CALL                                         !1, 'set'
          7        SEND_VAL_EX                                              5
          8        DO_FCALL                                      0          
   40     9        NEW                                              $10     'Factory'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
   41    12        INIT_METHOD_CALL                                         !0, 'getInstance'
         13        DO_FCALL                                      0  $13     
         14        ASSIGN                                                   !3, $13
   42    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 class@anonymous:
Function __construct:
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 = 108) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgOW9
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instanciated'
          1      > JMPZ                                                     ~0, ->6
   16     2    >   NEW                                              $1      'RuntimeException'
          3        SEND_VAL_EX                                              'Could+not+instanciate+class'
          4        DO_FCALL                                      0          
          5      > THROW                                         0          $1
   18     6    >   ASSIGN_STATIC_PROP                                       'instanciated'
          7        OP_DATA                                                  <true>
   19     8      > 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/HgOW9
function name:  get
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   FETCH_OBJ_R                                      ~0      'var'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   25     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/HgOW9
function name:  set
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'var'
          2        OP_DATA                                                  !0
   29     3      > RETURN                                                   null

End of function set

End of class class@anonymous.

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

End of function getinstance

End of class Factory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.47 ms | 946 KiB | 16 Q