3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected $c; protected $d; public function set(B $test) { static $testMap = []; if (empty($testMap)) { $testMap = [ C::class => [$this, 'setC'], D::class => [$this, 'setD'], ]; } if ($test === null) { return; } $testType = get_class($test); if (!array_key_exists($testType, $testMap)) { throw new InvalidArgumentException( sprintf( "Encountered unexpected body type (%s) that isn't supported", $testType ) ); } call_user_func($testMap[$testType], $test); } /** * @param C|null $c */ public function setC(C $c = null) { $this->c = $c; } /** * @param D|null $d */ public function setD(D $d = null) { $this->d = $d; } } abstract class B { protected $data; public function __construct($q = '') { $this->data = $q; } } class C extends B { } class D extends B {} $a1 = new A; $a1->set(new C("test c1")); var_dump($a1); $a2 = new A; $a2->set(new C("test c2")); var_dump($a2); $a3 = new A; $a3->set(new C("test c3")); var_dump($a3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  (null)
number of ops:  37
compiled vars:  !0 = $a1, !1 = $a2, !2 = $a3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   NEW                                              $3      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   63     3        INIT_METHOD_CALL                                         !0, 'set'
          4        NEW                                              $6      'C'
          5        SEND_VAL_EX                                              'test+c1'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $6
          8        DO_FCALL                                      0          
   64     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
   66    12        NEW                                              $10     'A'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $10
   67    15        INIT_METHOD_CALL                                         !1, 'set'
         16        NEW                                              $13     'C'
         17        SEND_VAL_EX                                              'test+c2'
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $13
         20        DO_FCALL                                      0          
   68    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                                 
   70    24        NEW                                              $17     'A'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !2, $17
   71    27        INIT_METHOD_CALL                                         !2, 'set'
         28        NEW                                              $20     'C'
         29        SEND_VAL_EX                                              'test+c3'
         30        DO_FCALL                                      0          
         31        SEND_VAR_NO_REF_EX                                       $20
         32        DO_FCALL                                      0          
   72    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Class A:
Function set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 29
Branch analysis from position: 21
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ta03s
function name:  set
number of ops:  34
compiled vars:  !0 = $test, !1 = $testMap, !2 = $testType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        BIND_STATIC                                              !1
    9     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~3, ->13
   11     4    >   FETCH_THIS                                       ~4      
          5        INIT_ARRAY                                       ~5      ~4
          6        ADD_ARRAY_ELEMENT                                ~5      'setC'
          7        INIT_ARRAY                                       ~6      ~5, 'C'
   12     8        FETCH_THIS                                       ~7      
          9        INIT_ARRAY                                       ~8      ~7
         10        ADD_ARRAY_ELEMENT                                ~8      'setD'
         11        ADD_ARRAY_ELEMENT                                ~6      ~8, 'D'
   10    12        ASSIGN                                                   !1, ~6
   15    13    >   TYPE_CHECK                                    2          !0
         14      > JMPZ                                                     ~10, ->16
   16    15    > > RETURN                                                   null
   18    16    >   GET_CLASS                                        ~11     !0
         17        ASSIGN                                                   !2, ~11
   19    18        ARRAY_KEY_EXISTS                                 ~13     !2, !1
         19        BOOL_NOT                                         ~14     ~13
         20      > JMPZ                                                     ~14, ->29
   20    21    >   NEW                                              $15     'InvalidArgumentException'
   21    22        INIT_FCALL                                               'sprintf'
   22    23        SEND_VAL                                                 'Encountered+unexpected+body+type+%28%25s%29+that+isn%27t+supported'
   23    24        SEND_VAR                                                 !2
         25        DO_ICALL                                         $16     
         26        SEND_VAR_NO_REF_EX                                       $16
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $15
   27    29    >   FETCH_DIM_R                                      ~18     !1, !2
         30        INIT_USER_CALL                                1          'call_user_func', ~18
         31        SEND_USER                                                !0
         32        DO_FCALL                                      0          
   28    33      > RETURN                                                   null

End of function set

Function setc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  setC
number of ops:  4
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV_INIT                                        !0      null
   35     1        ASSIGN_OBJ                                               'c'
          2        OP_DATA                                                  !0
   36     3      > RETURN                                                   null

End of function setc

Function setd:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  setD
number of ops:  4
compiled vars:  !0 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV_INIT                                        !0      null
   43     1        ASSIGN_OBJ                                               'd'
          2        OP_DATA                                                  !0
   44     3      > RETURN                                                   null

End of function setd

End of class A.

Class B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  __construct
number of ops:  4
compiled vars:  !0 = $q
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV_INIT                                        !0      ''
   52     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   53     3      > RETURN                                                   null

End of function __construct

End of class B.

Class C:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  __construct
number of ops:  4
compiled vars:  !0 = $q
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV_INIT                                        !0      ''
   52     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   53     3      > RETURN                                                   null

End of function __construct

End of class C.

Class D:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ta03s
function name:  __construct
number of ops:  4
compiled vars:  !0 = $q
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV_INIT                                        !0      ''
   52     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   53     3      > RETURN                                                   null

End of function __construct

End of class D.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.9 ms | 952 KiB | 18 Q