3v4l.org

run code in 500+ 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 = 28
Branch analysis from position: 21
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ta03s
function name:  set
number of ops:  33
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, ->28
   20    21    >   NEW                                                  $15     'InvalidArgumentException'
   23    22        ROPE_INIT                                         3  ~17     'Encountered+unexpected+body+type+%28'
         23        ROPE_ADD                                          1  ~17     ~17, !2
         24        ROPE_END                                          2  ~16     ~17, '%29+that+isn%27t+supported'
         25        SEND_VAL_EX                                                  ~16
   20    26        DO_FCALL                                          0          
   23    27      > THROW                                             0          $15
   27    28    >   FETCH_DIM_R                                          ~20     !1, !2
         29        INIT_USER_CALL                                    1          'call_user_func', ~20
         30        SEND_USER                                                    !0
         31        DO_FCALL                                          0          
   28    32      > 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.5.0


preferences:
157.98 ms | 2823 KiB | 9 Q