File tree 4 files changed +94
-0
lines changed
Zend/tests/attributes/constants
4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Validation of attribute repetition (not allowed; internal attribute)
3
+ --FILE--
4
+ <?php
5
+
6
+ #[Deprecated]
7
+ #[Deprecated]
8
+ const MY_CONST = true ;
9
+
10
+ ?>
11
+ --EXPECTF--
12
+ Fatal error: Attribute "Deprecated" must not be repeated in %s on line %d
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Validation of attribute repetition (not allowed; userland attribute)
3
+ --FILE--
4
+ <?php
5
+
6
+ #[Attribute]
7
+ class MyAttribute {}
8
+
9
+ #[MyAttribute]
10
+ #[MyAttribute]
11
+ const MY_CONST = true ;
12
+
13
+ $ attributes = new ReflectionConstant ( 'MY_CONST ' )->getAttributes ();
14
+ var_dump ( $ attributes );
15
+ $ attributes [0 ]->newInstance ();
16
+
17
+ ?>
18
+ --EXPECTF--
19
+ array(2) {
20
+ [0]=>
21
+ object(ReflectionAttribute)#%d (1) {
22
+ ["name"]=>
23
+ string(11) "MyAttribute"
24
+ }
25
+ [1]=>
26
+ object(ReflectionAttribute)#%d (1) {
27
+ ["name"]=>
28
+ string(11) "MyAttribute"
29
+ }
30
+ }
31
+
32
+ Fatal error: Uncaught Error: Attribute "MyAttribute" must not be repeated in %s:%d
33
+ Stack trace:
34
+ #0 %s(%d): ReflectionAttribute->newInstance()
35
+ #1 {main}
36
+ thrown in %s on line %d
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Validation of attribute repetition (is allowed; internal attribute)
3
+ --EXTENSIONS--
4
+ zend_test
5
+ --FILE--
6
+ <?php
7
+
8
+ #[ZendTestRepeatableAttribute]
9
+ #[ZendTestRepeatableAttribute]
10
+ const MY_CONST = true ;
11
+
12
+ echo "Done \n" ;
13
+
14
+ ?>
15
+ --EXPECT--
16
+ Done
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Validation of attribute repetition (is allowed; userland attribute)
3
+ --FILE--
4
+ <?php
5
+
6
+ #[Attribute(Attribute::TARGET_ALL |Attribute::IS_REPEATABLE )]
7
+ class MyAttribute {}
8
+
9
+ #[MyAttribute]
10
+ #[MyAttribute]
11
+ const MY_CONST = true ;
12
+
13
+ $ attributes = new ReflectionConstant ( 'MY_CONST ' )->getAttributes ();
14
+ var_dump ( $ attributes );
15
+ $ attributes [0 ]->newInstance ();
16
+
17
+ ?>
18
+ --EXPECTF--
19
+ array(2) {
20
+ [0]=>
21
+ object(ReflectionAttribute)#%d (1) {
22
+ ["name"]=>
23
+ string(11) "MyAttribute"
24
+ }
25
+ [1]=>
26
+ object(ReflectionAttribute)#%d (1) {
27
+ ["name"]=>
28
+ string(11) "MyAttribute"
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments