1--TEST--
2Verify that parameter attributes for native functions correctly support arguments.
3--EXTENSIONS--
4zend_test
5--FILE--
6<?php
7
8$reflection = new ReflectionFunction("zend_test_parameter_with_attribute");
9$attribute = $reflection->getParameters()[0]->getAttributes()[0];
10var_dump($attribute->getArguments());
11var_dump($attribute->newInstance());
12
13$reflection = new ReflectionMethod("ZendTestClassWithMethodWithParameterAttribute", "no_override");
14$attribute = $reflection->getParameters()[0]->getAttributes()[0];
15var_dump($attribute->getArguments());
16var_dump($attribute->newInstance());
17
18$reflection = new ReflectionMethod("ZendTestClassWithMethodWithParameterAttribute", "override");
19$attribute = $reflection->getParameters()[0]->getAttributes()[0];
20var_dump($attribute->getArguments());
21var_dump($attribute->newInstance());
22
23$reflection = new ReflectionMethod("ZendTestChildClassWithMethodWithParameterAttribute", "no_override");
24$attribute = $reflection->getParameters()[0]->getAttributes()[0];
25var_dump($attribute->getArguments());
26var_dump($attribute->newInstance());
27
28$reflection = new ReflectionMethod("ZendTestChildClassWithMethodWithParameterAttribute", "override");
29$attribute = $reflection->getParameters()[0]->getAttributes()[0];
30var_dump($attribute->getArguments());
31var_dump($attribute->newInstance());
32
33class ChildClassWithNoAttribute extends ZendTestClassWithMethodWithParameterAttribute {
34	public function override(string $parameter): int
35	{
36		return 5;
37	}
38}
39
40$reflection = new ReflectionMethod("ChildClassWithNoAttribute", "no_override");
41$attribute = $reflection->getParameters()[0]->getAttributes()[0];
42var_dump($attribute->getArguments());
43var_dump($attribute->newInstance());
44
45$reflection = new ReflectionMethod("ChildClassWithNoAttribute", "override");
46var_dump(count($reflection->getParameters()[0]->getAttributes()));
47
48class ChildClassWithSameAttribute extends ZendTestClassWithMethodWithParameterAttribute {
49	public function override(#[ZendTestParameterAttribute("value5")] string $parameter): int
50	{
51		return 6;
52	}
53}
54
55$reflection = new ReflectionMethod("ChildClassWithSameAttribute", "no_override");
56$attribute = $reflection->getParameters()[0]->getAttributes()[0];
57var_dump($attribute->getArguments());
58var_dump($attribute->newInstance());
59
60$reflection = new ReflectionMethod("ChildClassWithSameAttribute", "override");
61$attribute = $reflection->getParameters()[0]->getAttributes()[0];
62var_dump($attribute->getArguments());
63var_dump($attribute->newInstance());
64
65#[\Attribute(\Attribute::TARGET_PARAMETER)]
66class SomeAttribute {
67  public function __construct(public string $someParam) { }
68}
69
70class ChildClassWithDifferentAttribute extends ZendTestClassWithMethodWithParameterAttribute {
71	public function override(#[SomeAttribute("value6")] string $parameter): int
72	{
73		return 7;
74	}
75}
76
77$reflection = new ReflectionMethod("ChildClassWithDifferentAttribute", "no_override");
78$attribute = $reflection->getParameters()[0]->getAttributes()[0];
79var_dump($attribute->getArguments());
80var_dump($attribute->newInstance());
81
82$reflection = new ReflectionMethod("ChildClassWithDifferentAttribute", "override");
83$attribute = $reflection->getParameters()[0]->getAttributes()[0];
84var_dump($attribute->getArguments());
85var_dump($attribute->newInstance());
86
87?>
88--EXPECTF--
89array(1) {
90  [0]=>
91  string(6) "value1"
92}
93object(ZendTestParameterAttribute)#%d (1) {
94  ["parameter"]=>
95  string(6) "value1"
96}
97array(1) {
98  [0]=>
99  string(6) "value2"
100}
101object(ZendTestParameterAttribute)#%d (1) {
102  ["parameter"]=>
103  string(6) "value2"
104}
105array(1) {
106  [0]=>
107  string(6) "value3"
108}
109object(ZendTestParameterAttribute)#%d (1) {
110  ["parameter"]=>
111  string(6) "value3"
112}
113array(1) {
114  [0]=>
115  string(6) "value2"
116}
117object(ZendTestParameterAttribute)#%d (1) {
118  ["parameter"]=>
119  string(6) "value2"
120}
121array(1) {
122  [0]=>
123  string(6) "value4"
124}
125object(ZendTestParameterAttribute)#%d (1) {
126  ["parameter"]=>
127  string(6) "value4"
128}
129array(1) {
130  [0]=>
131  string(6) "value2"
132}
133object(ZendTestParameterAttribute)#%d (1) {
134  ["parameter"]=>
135  string(6) "value2"
136}
137int(0)
138array(1) {
139  [0]=>
140  string(6) "value2"
141}
142object(ZendTestParameterAttribute)#%d (1) {
143  ["parameter"]=>
144  string(6) "value2"
145}
146array(1) {
147  [0]=>
148  string(6) "value5"
149}
150object(ZendTestParameterAttribute)#%d (1) {
151  ["parameter"]=>
152  string(6) "value5"
153}
154array(1) {
155  [0]=>
156  string(6) "value2"
157}
158object(ZendTestParameterAttribute)#%d (1) {
159  ["parameter"]=>
160  string(6) "value2"
161}
162array(1) {
163  [0]=>
164  string(6) "value6"
165}
166object(SomeAttribute)#%d (1) {
167  ["someParam"]=>
168  string(6) "value6"
169}
170