You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec.md
+49
Original file line number
Diff line number
Diff line change
@@ -128,6 +128,55 @@ Any new types and keywords added to future PHP versions MUST be in lower case.
128
128
Short form of type keywords MUST be used i.e. `bool` instead of `boolean`,
129
129
`int` instead of `integer` etc.
130
130
131
+
Compound types includes intersection, union, and mixed intersection and union type declarations. PHP requires
132
+
that all compound types be structured as an ORed (unioned) series of ANDs (intersections), and that each set of
133
+
intersections be encased with parentheses.
134
+
135
+
The union symbol `|` and intersection symbol `&` MUST NOT have a leading or trailing space. The parentheses MUST NOT
136
+
have a leading or trailing space.
137
+
138
+
If it is necessary to split a compound type into multiple lines:
139
+
140
+
* If the type contains only intersections or only unions, then each line MUST have a single type.
141
+
* If the type contains both intersections and unions, then each line MUST have a single union segment. All intersections in a segment MUST be on the same line.
142
+
* The symbol on which the compound type is split MUST be at the start of each line.
143
+
144
+
The following are correct ways to format compound types:
145
+
146
+
```php
147
+
function foo(int|string $a): User|Product
148
+
{
149
+
// ...
150
+
}
151
+
152
+
function somethingWithReflection(
153
+
\RelfectionObject
154
+
|\ReflectionClass
155
+
|\ReflectionMethod
156
+
|\ReflectionParameter
157
+
|\ReflectionProperty $reflect
158
+
): object|null {
159
+
// ...
160
+
}
161
+
162
+
function complex(array|(ArrayAccess&Traversable) $input): ArrayAccess&Traversable
0 commit comments