Skip to content

Commit 214c435

Browse files
committed
Added support for empty arg list. Added AST evaluation test case.
1 parent 13db356 commit 214c435

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Zend/zend_language_parser.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ attribute_arguments:
322322
attribute_decl:
323323
class_name_reference
324324
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
325+
| class_name_reference '(' ')'
326+
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
325327
| class_name_reference '(' attribute_arguments ')'
326328
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, $3); }
327329
;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
Attributes can deal with AST nodes.
3+
--FILE--
4+
<?php
5+
6+
define('V1', strtoupper(php_sapi_name()));
7+
8+
<<A1([V1 => V1])>>
9+
class C1
10+
{
11+
public const BAR = 'bar';
12+
}
13+
14+
$ref = new \ReflectionClass(C1::class);
15+
$attr = $ref->getAttributes();
16+
var_dump(count($attr));
17+
18+
$args = $attr[0]->getArguments();
19+
var_dump(count($args), $args[0][V1] === V1);
20+
21+
echo "\n";
22+
23+
<<A1(V1, 1 + 2, C1::class)>>
24+
class C2 { }
25+
26+
$ref = new \ReflectionClass(C2::class);
27+
$attr = $ref->getAttributes();
28+
var_dump(count($attr));
29+
30+
$args = $attr[0]->getArguments();
31+
var_dump(count($args));
32+
var_dump($args[0] === V1);
33+
var_dump($args[1] === 3);
34+
var_dump($args[2] === C1::class);
35+
36+
echo "\n";
37+
38+
<<A1(self::FOO, C1::BAR)>>
39+
class C3
40+
{
41+
private const FOO = 'foo';
42+
}
43+
44+
$ref = new \ReflectionClass(C3::class);
45+
$attr = $ref->getAttributes();
46+
var_dump(count($attr));
47+
48+
$args = $attr[0]->getArguments();
49+
var_dump(count($args));
50+
var_dump($args[0] === 'foo');
51+
var_dump($args[1] === C1::BAR);
52+
53+
?>
54+
--EXPECT--
55+
int(1)
56+
int(1)
57+
bool(true)
58+
59+
int(1)
60+
int(3)
61+
bool(true)
62+
bool(true)
63+
bool(true)
64+
65+
int(1)
66+
int(2)
67+
bool(true)
68+
bool(true)

0 commit comments

Comments
 (0)