3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[\Attribute] final class Attr { public function __construct( public string $string, public int $int, ) {} } final class A { public function __construct( #[Attr(string: 'a', int: 1)] public string $a ) {} } $reflection = new \ReflectionClass(A::class); var_dump($reflection->getConstructor()->getParameters()[0]->getAttributes()[0]->getTarget() === \Attribute::TARGET_PARAMETER); var_dump($reflection->getProperty('a')->getAttributes()[0]->getTarget() === \Attribute::TARGET_PROPERTY);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rpM1t
function name:  (null)
number of ops:  31
compiled vars:  !0 = $reflection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'ReflectionClass'
          1        SEND_VAL_EX                                              'A'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   22     4        INIT_FCALL                                               'var_dump'
          5        INIT_METHOD_CALL                                         !0, 'getConstructor'
          6        DO_FCALL                                      0  $4      
          7        INIT_METHOD_CALL                                         $4, 'getParameters'
          8        DO_FCALL                                      0  $5      
          9        FETCH_DIM_R                                      ~6      $5, 0
         10        INIT_METHOD_CALL                                         ~6, 'getAttributes'
         11        DO_FCALL                                      0  $7      
         12        FETCH_DIM_R                                      ~8      $7, 0
         13        INIT_METHOD_CALL                                         ~8, 'getTarget'
         14        DO_FCALL                                      0  $9      
         15        IS_IDENTICAL                                     ~10     $9, 32
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                                 
   23    18        INIT_FCALL                                               'var_dump'
         19        INIT_METHOD_CALL                                         !0, 'getProperty'
         20        SEND_VAL_EX                                              'a'
         21        DO_FCALL                                      0  $12     
         22        INIT_METHOD_CALL                                         $12, 'getAttributes'
         23        DO_FCALL                                      0  $13     
         24        FETCH_DIM_R                                      ~14     $13, 0
         25        INIT_METHOD_CALL                                         ~14, 'getTarget'
         26        DO_FCALL                                      0  $15     
         27        IS_IDENTICAL                                     ~16     $15, 8
         28        SEND_VAL                                                 ~16
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Class Attr:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rpM1t
function name:  __construct
number of ops:  7
compiled vars:  !0 = $string, !1 = $int
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'string'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'int'
          5        OP_DATA                                                  !1
    9     6      > RETURN                                                   null

End of function __construct

End of class Attr.

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rpM1t
function name:  __construct
number of ops:  4
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'a'
          2        OP_DATA                                                  !0
   17     3      > RETURN                                                   null

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.2 ms | 1450 KiB | 14 Q