@@ -6,68 +6,68 @@ Attributes can be converted into objects.
6
6
#[Attribute(Attribute::TARGET_FUNCTION )]
7
7
class A1
8
8
{
9
- public string $ name ;
10
- public int $ ttl ;
11
-
12
- public function __construct (string $ name , int $ ttl = 50 )
13
- {
14
- $ this ->name = $ name ;
15
- $ this ->ttl = $ ttl ;
16
- }
9
+ public string $ name ;
10
+ public int $ ttl ;
11
+
12
+ public function __construct (string $ name , int $ ttl = 50 )
13
+ {
14
+ $ this ->name = $ name ;
15
+ $ this ->ttl = $ ttl ;
16
+ }
17
17
}
18
18
19
19
$ ref = new \ReflectionFunction (#[A1 ('test ' )] function () { });
20
20
21
21
foreach ($ ref ->getAttributes () as $ attr ) {
22
- $ obj = $ attr ->newInstance ();
22
+ $ obj = $ attr ->newInstance ();
23
23
24
- var_dump (get_class ($ obj ), $ obj ->name , $ obj ->ttl );
24
+ var_dump (get_class ($ obj ), $ obj ->name , $ obj ->ttl );
25
25
}
26
26
27
27
echo "\n" ;
28
28
29
29
$ ref = new \ReflectionFunction (#[A1 ] function () { });
30
30
31
31
try {
32
- $ ref ->getAttributes ()[0 ]->newInstance ();
32
+ $ ref ->getAttributes ()[0 ]->newInstance ();
33
33
} catch (\ArgumentCountError $ e ) {
34
- var_dump ('ERROR 1 ' , $ e ->getMessage ());
34
+ var_dump ('ERROR 1 ' , $ e ->getMessage ());
35
35
}
36
36
37
37
echo "\n" ;
38
38
39
39
$ ref = new \ReflectionFunction (#[A1 ([])] function () { });
40
40
41
41
try {
42
- $ ref ->getAttributes ()[0 ]->newInstance ();
42
+ $ ref ->getAttributes ()[0 ]->newInstance ();
43
43
} catch (\TypeError $ e ) {
44
- var_dump ('ERROR 2 ' , $ e ->getMessage ());
44
+ var_dump ('ERROR 2 ' , $ e ->getMessage ());
45
45
}
46
46
47
47
echo "\n" ;
48
48
49
49
$ ref = new \ReflectionFunction (#[A2 ] function () { });
50
50
51
51
try {
52
- $ ref ->getAttributes ()[0 ]->newInstance ();
52
+ $ ref ->getAttributes ()[0 ]->newInstance ();
53
53
} catch (\Error $ e ) {
54
- var_dump ('ERROR 3 ' , $ e ->getMessage ());
54
+ var_dump ('ERROR 3 ' , $ e ->getMessage ());
55
55
}
56
56
57
57
echo "\n" ;
58
58
59
59
#[Attribute]
60
60
class A3
61
61
{
62
- private function __construct () { }
62
+ private function __construct () { }
63
63
}
64
64
65
65
$ ref = new \ReflectionFunction (#[A3 ] function () { });
66
66
67
67
try {
68
- $ ref ->getAttributes ()[0 ]->newInstance ();
68
+ $ ref ->getAttributes ()[0 ]->newInstance ();
69
69
} catch (\Error $ e ) {
70
- var_dump ('ERROR 4 ' , $ e ->getMessage ());
70
+ var_dump ('ERROR 4 ' , $ e ->getMessage ());
71
71
}
72
72
73
73
echo "\n" ;
@@ -78,9 +78,9 @@ class A4 { }
78
78
$ ref = new \ReflectionFunction (#[A4 (1 )] function () { });
79
79
80
80
try {
81
- $ ref ->getAttributes ()[0 ]->newInstance ();
81
+ $ ref ->getAttributes ()[0 ]->newInstance ();
82
82
} catch (\Error $ e ) {
83
- var_dump ('ERROR 5 ' , $ e ->getMessage ());
83
+ var_dump ('ERROR 5 ' , $ e ->getMessage ());
84
84
}
85
85
86
86
echo "\n" ;
@@ -90,9 +90,9 @@ class A5 { }
90
90
$ ref = new \ReflectionFunction (#[A5 ] function () { });
91
91
92
92
try {
93
- $ ref ->getAttributes ()[0 ]->newInstance ();
93
+ $ ref ->getAttributes ()[0 ]->newInstance ();
94
94
} catch (\Error $ e ) {
95
- var_dump ('ERROR 6 ' , $ e ->getMessage ());
95
+ var_dump ('ERROR 6 ' , $ e ->getMessage ());
96
96
}
97
97
98
98
?>
0 commit comments