xref: /PHP-8.3/Zend/tests/traits/constant_020.phpt (revision 3b62d660)
1--TEST--
2Attributes can be retrieved from trait constants
3--FILE--
4<?php
5
6class TestAttribute {
7    public function __construct(public string $value) {}
8}
9
10trait TestTrait {
11  #[TestAttribute(value: 123)]
12  public const Constant = 42;
13}
14
15class TestClass {
16  use TestTrait;
17}
18
19$reflection = new \ReflectionClass(TestTrait::class);
20var_dump($reflection->getReflectionConstant('Constant')->getAttributes('TestAttribute')[0]->getArguments()['value']);
21
22$reflection = new \ReflectionClass(TestClass::class);
23var_dump($reflection->getReflectionConstant('Constant')->getAttributes('TestAttribute')[0]->getArguments()['value']);
24
25?>
26--EXPECTF--
27int(123)
28int(123)
29