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; echo "new instance\n"; } 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(); try { $o2 = $factory->getInstance(); echo "instance returned\n"; var_dump($o2->get()); } catch (Throwable $e) { echo "Non: ", $e->getMessage(), "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 22
Branch analysis from position: 22
2 jumps found. (Code = 107) Position 1 = 23, Position 2 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2f70V
function name:  (null)
number of ops:  29
compiled vars:  !0 = $factory, !1 = $o, !2 = $factory2, !3 = $o2, !4 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   NEW                                              $5      'Factory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
   41     3        INIT_METHOD_CALL                                         !0, 'getInstance'
          4        DO_FCALL                                      0  $8      
          5        ASSIGN                                                   !1, $8
   42     6        INIT_METHOD_CALL                                         !1, 'set'
          7        SEND_VAL_EX                                              5
          8        DO_FCALL                                      0          
   44     9        NEW                                              $11     'Factory'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $11
   46    12        INIT_METHOD_CALL                                         !0, 'getInstance'
         13        DO_FCALL                                      0  $14     
         14        ASSIGN                                                   !3, $14
   47    15        ECHO                                                     'instance+returned%0A'
   48    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !3, 'get'
         18        DO_FCALL                                      0  $16     
         19        SEND_VAR                                                 $16
         20        DO_ICALL                                                 
         21      > JMP                                                      ->28
   49    22  E > > CATCH                                       last         'Throwable'
   50    23    >   ECHO                                                     'Non%3A+'
         24        INIT_METHOD_CALL                                         !4, 'getMessage'
         25        DO_FCALL                                      0  $18     
         26        ECHO                                                     $18
         27        ECHO                                                     '%0A'
   51    28    > > 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/2f70V
function name:  __construct
number of ops:  11
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        ECHO                                                     'new+instance%0A'
   13    10      > 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/2f70V
function name:  get
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                      ~0      'var'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   19     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/2f70V
function name:  set
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN_OBJ                                               'var'
          2        OP_DATA                                                  !0
   23     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/2f70V
function name:  getInstance
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   ECHO                                                     'getInstance%28%29%0A'
   33     1        FETCH_OBJ_R                                      ~0      'instance'
          2        TYPE_CHECK                                    2          ~0
          3      > JMPZ                                                     ~1, ->8
   34     4    >   NEW                                              $3      'Singleton'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'instance'
          7        OP_DATA                                                  $3
   36     8    >   FETCH_OBJ_R                                      ~5      'instance'
          9      > RETURN                                                   ~5
   37    10*     > RETURN                                                   null

End of function getinstance

End of class Factory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.58 ms | 1400 KiB | 15 Q