1--TEST--
2Attributes can deal with AST nodes.
3--FILE--
4<?php
5
6define('V1', strtoupper(php_sapi_name()));
7
8#[A1([V1 => V1])]
9class C1
10{
11    public const BAR = 'bar';
12}
13
14$ref = new \ReflectionClass(C1::class);
15$attr = $ref->getAttributes();
16var_dump(count($attr));
17
18$args = $attr[0]->getArguments();
19var_dump(count($args), $args[0][V1] === V1);
20
21echo "\n";
22
23#[A1(V1, 1 + 2, C1::class)]
24class C2 { }
25
26$ref = new \ReflectionClass(C2::class);
27$attr = $ref->getAttributes();
28var_dump(count($attr));
29
30$args = $attr[0]->getArguments();
31var_dump(count($args));
32var_dump($args[0] === V1);
33var_dump($args[1] === 3);
34var_dump($args[2] === C1::class);
35
36echo "\n";
37
38#[A1(self::FOO, C1::BAR)]
39class C3
40{
41    private const FOO = 'foo';
42}
43
44$ref = new \ReflectionClass(C3::class);
45$attr = $ref->getAttributes();
46var_dump(count($attr));
47
48$args = $attr[0]->getArguments();
49var_dump(count($args));
50var_dump($args[0] === 'foo');
51var_dump($args[1] === C1::BAR);
52
53echo "\n";
54
55#[ExampleWithShift(4 >> 1)]
56class C4 {}
57$ref = new \ReflectionClass(C4::class);
58var_dump($ref->getAttributes()[0]->getArguments());
59
60echo "\n";
61
62#[Attribute]
63class C5
64{
65    public function __construct() { }
66}
67
68$ref = new \ReflectionFunction(#[C5(MissingClass::SOME_CONST)] function () { });
69$attr = $ref->getAttributes();
70var_dump(count($attr));
71
72try {
73    $attr[0]->getArguments();
74} catch (\Error $e) {
75    var_dump($e->getMessage());
76}
77
78try {
79    $attr[0]->newInstance();
80} catch (\Error $e) {
81    var_dump($e->getMessage());
82}
83
84?>
85--EXPECT--
86int(1)
87int(1)
88bool(true)
89
90int(1)
91int(3)
92bool(true)
93bool(true)
94bool(true)
95
96int(1)
97int(2)
98bool(true)
99bool(true)
100
101array(1) {
102  [0]=>
103  int(2)
104}
105
106int(1)
107string(30) "Class "MissingClass" not found"
108string(30) "Class "MissingClass" not found"
109