3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface MyInterface { public function get(): int; public function set(int $value); } class Factory { private $instance = null; public function getInstance(): MyInterface { if ($this->instance === null) { $this->instance = new class() implements MyInterface { 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; } } function display(MyInterface $object) { var_dump($object->get()); } $factory = new Factory(); $o = $factory->getInstance(); $o->set(5); $o2 = $factory->getInstance(); display($o2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pG7Ld
function name:  (null)
number of ops:  16
compiled vars:  !0 = $factory, !1 = $o, !2 = $o2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $3      'Factory'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   47     3        INIT_METHOD_CALL                                         !0, 'getInstance'
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !1, $6
   48     6        INIT_METHOD_CALL                                         !1, 'set'
          7        SEND_VAL_EX                                              5
          8        DO_FCALL                                      0          
   49     9        INIT_METHOD_CALL                                         !0, 'getInstance'
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !2, $9
   51    12        INIT_FCALL                                               'display'
         13        SEND_VAR                                                 !2
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Function display:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pG7Ld
function name:  display
number of ops:  7
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'var_dump'
          2        INIT_METHOD_CALL                                         !0, 'get'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   44     6      > RETURN                                                   null

End of function display

Class MyInterface:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pG7Ld
function name:  get
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   VERIFY_RETURN_TYPE                                       
          1      > 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/pG7Ld
function name:  set
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function set

End of class MyInterface.

Class MyInterface@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/pG7Ld
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'instanciated'
          1      > JMPZ                                                     ~0, ->6
   21     2    >   NEW                                              $1      'RuntimeException'
          3        SEND_VAL_EX                                              'Could+not+instanciate+class'
          4        DO_FCALL                                      0          
          5      > THROW                                         0          $1
   23     6    >   ASSIGN_STATIC_PROP                                       'instanciated'
          7        OP_DATA                                                  <true>
   24     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/pG7Ld
function name:  get
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'var'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   30     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/pG7Ld
function name:  set
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        ASSIGN_OBJ                                               'var'
          2        OP_DATA                                                  !0
   34     3      > RETURN                                                   null

End of function set

End of class MyInterface@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/pG7Ld
function name:  getInstance
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'instance'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->8
   15     3    >   DECLARE_ANON_CLASS                               <unknown> 
          4        NEW                                              $4      $3
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'instance'
          7        OP_DATA                                                  $4
   37     8    >   FETCH_OBJ_R                                      ~6      'instance'
          9        VERIFY_RETURN_TYPE                                       ~6
         10      > RETURN                                                   ~6
   38    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function getinstance

End of class Factory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.22 ms | 1398 KiB | 16 Q