1--TEST--
2Named params in attributes
3--FILE--
4<?php
5
6#[Attribute]
7class MyAttribute {
8    public function __construct(
9        public $a = 'a',
10        public $b = 'b',
11        public $c = 'c',
12    ) {}
13}
14
15#[MyAttribute('A', c: 'C')]
16class Test1 {}
17
18#[MyAttribute('A', a: 'C')]
19class Test2 {}
20
21$attr = (new ReflectionClass(Test1::class))->getAttributes()[0];
22var_dump($attr->getName());
23var_dump($attr->getArguments());
24var_dump($attr->newInstance());
25
26$attr = (new ReflectionClass(Test2::class))->getAttributes()[0];
27try {
28    var_dump($attr->newInstance());
29} catch (Error $e) {
30    echo $e->getMessage(), "\n";
31}
32
33?>
34--EXPECT--
35string(11) "MyAttribute"
36array(2) {
37  [0]=>
38  string(1) "A"
39  ["c"]=>
40  string(1) "C"
41}
42object(MyAttribute)#1 (3) {
43  ["a"]=>
44  string(1) "A"
45  ["b"]=>
46  string(1) "b"
47  ["c"]=>
48  string(1) "C"
49}
50Named parameter $a overwrites previous argument
51