Skip to content

Commit f28cace

Browse files
Better test for named parameters
To show why the ZEND_AST_NAMED_ARG handling is needed
1 parent 92b248a commit f28cace

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Zend/tests/attributes/constants/allow_named_parameters.phpt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ Verify that named parameters can be passed to attributes on constants
33
--FILE--
44
<?php
55

6-
#[MyAttribute(foo: "bar")]
7-
const EXAMPLE = 'Foo';
6+
#[Attribute]
7+
class MyAttribute {
8+
public function __construct($first, $second) {
9+
echo "first: $first\n";
10+
echo "second: $second\n";
11+
}
12+
}
13+
14+
#[MyAttribute(second: "bar", first: "foo")]
15+
const EXAMPLE = 'ignored';
816

917
$ref = new ReflectionConstant('EXAMPLE');
1018
$attribs = $ref->getAttributes();
1119
var_dump($attribs);
1220
var_dump($attribs[0]->getArguments());
21+
$attribs[0]->newInstance();
1322

1423
?>
1524
--EXPECTF--
@@ -20,7 +29,11 @@ array(1) {
2029
string(11) "MyAttribute"
2130
}
2231
}
23-
array(1) {
24-
["foo"]=>
32+
array(2) {
33+
["second"]=>
2534
string(3) "bar"
35+
["first"]=>
36+
string(3) "foo"
2637
}
38+
first: foo
39+
second: bar

0 commit comments

Comments
 (0)