1
+ <?php
2
+ /**
3
+ * Parser Reflection API
4
+ *
5
+ * @copyright Copyright 2016, Lisachenko Alexander <[email protected] >
6
+ *
7
+ * This source file is subject to the license that is bundled
8
+ * with this source code in the file LICENSE.
9
+ */
10
+ declare (strict_types=1 );
11
+
12
+ namespace Go \ParserReflection \Stub ;
13
+
14
+ use Attribute ;
15
+ use Go \ParserReflection \{ReflectionMethod , ReflectionProperty as P };
16
+
17
+ class ClassWithPhp80Features
18
+ {
19
+ public function acceptsStringArrayDefaultToNull (array |string $ iterable = null ) : array {}
20
+ }
21
+
22
+ /**
23
+ * @see https://php.watch/versions/8.0/named-parameters
24
+ */
25
+ class ClassWithPHP80NamedCall
26
+ {
27
+ public static function foo (string $ key1 = '' , string $ key2 = '' ): string
28
+ {
29
+ return $ key1 . ': ' . $ key2 ;
30
+ }
31
+
32
+ public static function namedCall (): array
33
+ {
34
+ return [
35
+ 'key1 ' => \Go \ParserReflection \Stub \ClassWithPHP80NamedCall::foo (key1: 'bar ' ),
36
+ 'key2 ' => \Go \ParserReflection \Stub \ClassWithPHP80NamedCall::foo (key2: 'baz ' ),
37
+ 'keys ' => \Go \ParserReflection \Stub \ClassWithPHP80NamedCall::foo (key1: 'A ' , key2: 'B ' ),
38
+ 'reverseKeys ' => \Go \ParserReflection \Stub \ClassWithPHP80NamedCall::foo (key2: 'A ' , key1: 'B ' ),
39
+ 'unpack ' => \Go \ParserReflection \Stub \ClassWithPHP80NamedCall::foo (...['key1 ' => 'C ' , 'key2 ' => 'D ' ]),
40
+ ];
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @see https://php.watch/versions/8.0/attributes
46
+ */
47
+ #[Attribute(Attribute::TARGET_ALL | Attribute::IS_REPEATABLE )]
48
+ readonly class ClassPHP80Attribute
49
+ {
50
+ private string $ value ;
51
+
52
+ public function __construct (string $ value )
53
+ {
54
+ $ this ->value = $ value ;
55
+ }
56
+
57
+ public function getValue (): string
58
+ {
59
+ return $ this ->value ;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * @see https://php.watch/versions/8.0/attributes
65
+ */
66
+ #[ClassPHP80Attribute('class ' )]
67
+ class ClassPHP80WithAttribute
68
+ {
69
+ #[ClassPHP80Attribute('first ' )]
70
+ #[ClassPHP80Attribute('second ' )]
71
+ public const PUBLIC_CONST = 1 ;
72
+
73
+ #[ClassPHP80Attribute('property ' )]
74
+ private string $ privateProperty = 'foo ' ;
75
+
76
+ #[ClassPHP80Attribute('method ' )]
77
+ public function bar (#[ClassPHP80Attribute('parameter ' )] $ parameter )
78
+ {}
79
+ }
80
+
81
+ /**
82
+ * @see https://php.watch/versions/8.0/constructor-property-promotion
83
+ */
84
+ class ClassPHP80WithPropertyPromotion
85
+ {
86
+ public function __construct (
87
+ private string $ privateStringValue ,
88
+ private $ privateNonTypedValue ,
89
+ protected int $ protectedIntValue = 42 ,
90
+ public array $ publicArrayValue = [M_PI , M_E ],
91
+ ) {}
92
+ }
93
+
94
+ /**
95
+ * @see https://php.watch/versions/8.0/union-types
96
+ */
97
+ class ClassWithPHP80UnionTypes
98
+ {
99
+ public string |int |float |bool $ scalarValue ;
100
+
101
+ public array |object |null $ complexValueOrNull = null ;
102
+
103
+ /**
104
+ * Special case, internally iterable should be replaced with Traversable|array
105
+ */
106
+ public iterable |object $ iterableOrObject ;
107
+
108
+ public static function returnsUnionType (): object |array |null {}
109
+
110
+ public static function acceptsUnionType (\stdClass |\Traversable |array $ iterable ): void {}
111
+ }
112
+
113
+ /**
114
+ * @see https://php.watch/versions/8.0/mixed-type
115
+ */
116
+ class ClassWithPHP80MixedType
117
+ {
118
+ public mixed $ someMixedPublicProperty ;
119
+
120
+ public static function returnsMixed (): mixed {}
121
+
122
+ public static function acceptsMixed (mixed $ value ): void {}
123
+ }
124
+
125
+ /**
126
+ * @see https://php.watch/versions/8.0/static-return-type
127
+ */
128
+ class ClassWithPHP80StaticReturnType
129
+ {
130
+ public static function create (): static {}
131
+ }
0 commit comments