File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Attributes can be retrieved from trait constants
3+ --FILE--
4+ <?php
5+
6+ class TestAttribute {
7+ public function __construct (public string $ value ) {}
8+ }
9+
10+ trait TestTrait {
11+ #[TestAttribute(value: 123 )]
12+ public const Constant = 42 ;
13+ }
14+
15+ class TestClass {
16+ use TestTrait;
17+ }
18+
19+ $ reflection = new \ReflectionClass (TestTrait::class);
20+ var_dump ($ reflection ->getReflectionConstant ('Constant ' )->getAttributes ('TestAttribute ' )[0 ]->getArguments ()['value ' ]);
21+
22+ $ reflection = new \ReflectionClass (TestClass::class);
23+ var_dump ($ reflection ->getReflectionConstant ('Constant ' )->getAttributes ('TestAttribute ' )[0 ]->getArguments ()['value ' ]);
24+
25+ ?>
26+ --EXPECTF--
27+ int(123)
28+ int(123)
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Doc comments can be retrieved from trait constants
3+ --FILE--
4+ <?php
5+
6+ trait TestTrait {
7+ /** DocComments */
8+ public const Constant = 42 ;
9+ }
10+
11+ class TestClass {
12+ use TestTrait;
13+ }
14+
15+ $ reflection = new \ReflectionClass (TestTrait::class);
16+ var_dump ($ reflection ->getReflectionConstant ('Constant ' )->getDocComment ());
17+
18+ $ reflection = new \ReflectionClass (TestClass::class);
19+ var_dump ($ reflection ->getReflectionConstant ('Constant ' )->getDocComment ());
20+
21+ ?>
22+ --EXPECTF--
23+ string(18) "/** DocComments */"
24+ string(18) "/** DocComments */"
You can’t perform that action at this time.
0 commit comments