File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
ext/reflection/tests/attributes Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,8 @@ attribute_arguments:
322
322
attribute_decl :
323
323
class_name_reference
324
324
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1 , NULL ); }
325
+ | class_name_reference ' (' ' )'
326
+ { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1 , NULL ); }
325
327
| class_name_reference ' (' attribute_arguments ' )'
326
328
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1 , $3 ); }
327
329
;
Original file line number Diff line number Diff line change
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)
You can’t perform that action at this time.
0 commit comments