3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface EntityInterface { } class EntityDecorator implements EntityInterface { public $subject; public function __construct(EntityInterface $subject) { $this->subject = $subject instanceof static ? $subject->getEntity() : $subject; } public function getEntity() { return $this->subject; } } class Entity implements EntityInterface {} class DecoratorA extends EntityDecorator {} class DecoratorB extends EntityDecorator {} $entity = new Entity(); var_dump($entity); $a = new DecoratorA($entity); var_dump($a); $b = new DecoratorB($a); var_dump($b); $b2 = new DecoratorB($b); var_dump($b2); $a2 = new DecoratorA($b2); var_dump($a2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tNU9S
function name:  (null)
number of ops:  39
compiled vars:  !0 = $entity, !1 = $a, !2 = $b, !3 = $b2, !4 = $a2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'entitydecorator'
   20     1        DECLARE_CLASS                                            'entity'
   22     2        DECLARE_CLASS                                            'decoratora', 'entitydecorator'
   24     3        DECLARE_CLASS                                            'decoratorb', 'entitydecorator'
   26     4        NEW                                              $5      'Entity'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $5
   27     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
   28    10        NEW                                              $9      'DecoratorA'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $9
   29    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   30    17        NEW                                              $13     'DecoratorB'
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !2, $13
   31    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                                 
   32    24        NEW                                              $17     'DecoratorB'
         25        SEND_VAR_EX                                              !2
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !3, $17
   33    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                                 
   34    31        NEW                                              $21     'DecoratorA'
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !4, $21
   36    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Class EntityInterface: [no user functions]
Class EntityDecorator:
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 = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tNU9S
function name:  __construct
number of ops:  11
compiled vars:  !0 = $subject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INSTANCEOF                                               !0
          2      > JMPZ                                                     ~2, ->7
          3    >   INIT_METHOD_CALL                                         !0, 'getEntity'
          4        DO_FCALL                                      0  $3      
          5        QM_ASSIGN                                        ~4      $3
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~4      !0
          8    >   ASSIGN_OBJ                                               'subject'
          9        OP_DATA                                                  ~4
   13    10      > RETURN                                                   null

End of function __construct

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

End of function getentity

End of class EntityDecorator.

Class Entity: [no user functions]
Class DecoratorA: [no user functions]
Class DecoratorB: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.9 ms | 1405 KiB | 15 Q