3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_PROPERTY)] ## Look ma, I'm not targeting parameter with Attribute::TARGET_PARAMETER final class TargetTestPropertyAttribute { } final class TargetTest { public function __construct( #[TargetTestAttribute] public string $test ) { } } $ref = new ReflectionClass(TargetTest::class); $testAsProperty = $ref->getProperty('test'); $testAsParemter = $ref->getConstructor()->getParameters()[0]; // Property echo $testAsProperty->getAttributes()[0]->getTarget() === Attribute::TARGET_PROPERTY ? "Attribute targets property\n" : "Attribute does not target property\n"; // Parameter echo $testAsParemter->getAttributes()[0]->getTarget() === Attribute::TARGET_PARAMETER ? "Attribute targets parameter (why?)\n" : "Attribute does not target parameter\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
Branch analysis from position: 34
filename:       /in/QMjAH
function name:  (null)
number of ops:  37
compiled vars:  !0 = $ref, !1 = $testAsProperty, !2 = $testAsParemter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $3      'ReflectionClass'
          1        SEND_VAL_EX                                              'TargetTest'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   19     4        INIT_METHOD_CALL                                         !0, 'getProperty'
          5        SEND_VAL_EX                                              'test'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
   20     8        INIT_METHOD_CALL                                         !0, 'getConstructor'
          9        DO_FCALL                                      0  $8      
         10        INIT_METHOD_CALL                                         $8, 'getParameters'
         11        DO_FCALL                                      0  $9      
         12        FETCH_DIM_R                                      ~10     $9, 0
         13        ASSIGN                                                   !2, ~10
   23    14        INIT_METHOD_CALL                                         !1, 'getAttributes'
         15        DO_FCALL                                      0  $12     
         16        FETCH_DIM_R                                      ~13     $12, 0
         17        INIT_METHOD_CALL                                         ~13, 'getTarget'
         18        DO_FCALL                                      0  $14     
         19        IS_IDENTICAL                                             $14, 8
         20      > JMPZ                                                     ~15, ->23
         21    >   QM_ASSIGN                                        ~16     'Attribute+targets+property%0A'
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~16     'Attribute+does+not+target+property%0A'
         24    >   ECHO                                                     ~16
   26    25        INIT_METHOD_CALL                                         !2, 'getAttributes'
         26        DO_FCALL                                      0  $17     
         27        FETCH_DIM_R                                      ~18     $17, 0
         28        INIT_METHOD_CALL                                         ~18, 'getTarget'
         29        DO_FCALL                                      0  $19     
         30        IS_IDENTICAL                                             $19, 32
         31      > JMPZ                                                     ~20, ->34
         32    >   QM_ASSIGN                                        ~21     'Attribute+targets+parameter+%28why%3F%29%0A'
         33      > JMP                                                      ->35
         34    >   QM_ASSIGN                                        ~21     'Attribute+does+not+target+parameter%0A'
         35    >   ECHO                                                     ~21
         36      > RETURN                                                   1

Class TargetTestPropertyAttribute: [no user functions]
Class TargetTest:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QMjAH
function name:  __construct
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'test'
          2        OP_DATA                                                  !0
   15     3      > RETURN                                                   null

End of function __construct

End of class TargetTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.09 ms | 1021 KiB | 14 Q