11<?php
22
3+ /* testImportUse */
4+ use Vendor \Package \Sub as Alias ;
5+
6+ /* testImportGroupUse */
7+ use Vendor \Package \Sub \{
8+ ClassA ,
9+ ClassB as BAlias ,
10+ };
11+
12+ if ($ foo ) {}
13+
14+ /* testTraitUse */
15+ class TraitUse {
16+ use ImportedTrait;
17+
18+ function methodName () {}
19+ }
20+
21+ /* testNotAFunction */
22+ interface NotAFunction {};
23+
24+ /* testFunctionNoParams */
25+ function noParams () {}
26+
327/* testPassByReference */
428function passByReference (&$ var ) {}
529
@@ -32,6 +56,75 @@ function myFunction($a = 10 & 20) {}
3256/* testArrowFunction */
3357fn (int $ a , ...$ b ) => $ b ;
3458
59+ /* testArrowFunctionReturnByRef */
60+ fn &(?string $ a ) => $ b ;
61+
62+ /* testArrayDefaultValues */
63+ function arrayDefaultValues ($ var1 = [], $ var2 = array (1 , 2 , 3 ) ) {}
64+
65+ /* testConstantDefaultValueSecondParam */
66+ function constantDefaultValueSecondParam ($ var1 , $ var2 = M_PI ) {}
67+
68+ /* testScalarTernaryExpressionInDefault */
69+ function ternayInDefault ( $ a = FOO ? 'bar ' : 10 , ? bool $ b ) {}
70+
71+ /* testVariadicFunction */
72+ function variadicFunction ( int ... $ a ) {}
73+
74+ /* testVariadicByRefFunction */
75+ function variadicByRefFunction ( &...$ a ) {}
76+
77+ /* testVariadicFunctionClassType */
78+ function variableLengthArgument ($ unit , DateInterval ...$ intervals ) {}
79+
80+ /* testNameSpacedTypeDeclaration */
81+ function namespacedClassType ( \Package \Sub \ClassName $ a , ?Sub \AnotherClass $ b ) {}
82+
83+ /* testWithAllTypes */
84+ class testAllTypes {
85+ function allTypes (
86+ ?ClassName $ a ,
87+ self $ b ,
88+ parent $ c ,
89+ object $ d ,
90+ ?int $ e ,
91+ string &$ f ,
92+ iterable $ g ,
93+ bool $ h = true ,
94+ callable $ i = 'is_null ' ,
95+ float $ j = 1.1 ,
96+ array ...$ k
97+ ) {}
98+ }
99+
100+ /* testArrowFunctionWithAllTypes */
101+ $ fn = fn (
102+ ?ClassName $ a ,
103+ self $ b ,
104+ parent $ c ,
105+ object $ d ,
106+ ?int $ e ,
107+ string &$ f ,
108+ iterable $ g ,
109+ bool $ h = true ,
110+ callable $ i = 'is_null ' ,
111+ float $ j = 1.1 ,
112+ array ...$ k
113+ ) => $ something ;
114+
115+ /* testMessyDeclaration */
116+ function messyDeclaration (
117+ // comment
118+ ?\MyNS /* comment */
119+ \ SubCat // phpcs:ignore Standard.Cat.Sniff -- for reasons.
120+ \ MyClass $ a ,
121+ $ b /* test */ = /* test */ 'default ' /* test*/ ,
122+ // phpcs:ignore Stnd.Cat.Sniff -- For reasons.
123+ ? /*comment*/
124+ bool // phpcs:disable Stnd.Cat.Sniff -- For reasons.
125+ & /*test*/ ... /* phpcs:ignore */ $ c
126+ ) {}
127+
35128/* testPHP8MixedTypeHint */
36129function mixedTypeHint (mixed &...$ var1 ) {}
37130
@@ -46,7 +139,7 @@ function namespaceOperatorTypeHint(?namespace\Name $var1) {}
46139function unionTypeSimple (int |float $ number , self |parent &...$ obj ) {}
47140
48141/* testPHP8UnionTypesWithSpreadOperatorAndReference */
49- function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
142+ function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
50143
51144/* testPHP8UnionTypesSimpleWithBitwiseOrInDefault */
52145$ fn = fn (int |float $ var = CONSTANT_A | CONSTANT_B ) => $ var ;
@@ -110,7 +203,13 @@ class ConstructorPropertyPromotionAndNormalParams {
110203
111204class ConstructorPropertyPromotionWithReadOnly {
112205 /* testPHP81ConstructorPropertyPromotionWithReadOnly */
113- public function __construct (public readonly ?int $ promotedProp , readonly private string |bool &$ promotedToo ) {}
206+ public function __construct (public readonly ?int $ promotedProp , ReadOnly private string |bool &$ promotedToo ) {}
207+ }
208+
209+ class ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration {
210+ /* testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration */
211+ // Intentional fatal error. Readonly properties MUST be typed.
212+ public function __construct (public readonly $ promotedProp , ReadOnly private &$ promotedToo ) {}
114213}
115214
116215class ConstructorPropertyPromotionWithOnlyReadOnly {
@@ -174,3 +273,49 @@ function pseudoTypeTrue(?true $var = true) {}
174273/* testPHP82PseudoTypeFalseAndTrue */
175274// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
176275function pseudoTypeFalseAndTrue (true |false $ var = true ) {}
276+
277+ /* testPHP81NewInInitializers */
278+ function newInInitializers (
279+ TypeA $ new = new TypeA (self ::CONST_VALUE ),
280+ \Package \TypeB $ newToo = new \Package \TypeB (10 , 'string ' ),
281+ ) {}
282+
283+ /* testFunctionCallFnPHPCS353-354 */
284+ $ value = $ obj ->fn (true );
285+
286+ /* testClosureNoParams */
287+ function () {};
288+
289+ /* testClosure */
290+ function ( $ a = 'test ' ) {};
291+
292+ /* testClosureUseNoParams */
293+ function () use () {};
294+
295+ /* testClosureUse */
296+ function () use ( $ foo , $ bar ) {};
297+
298+ /* testFunctionParamListWithTrailingComma */
299+ function trailingComma (
300+ ?string $ foo /*comment*/ ,
301+ $ bar = 0 ,
302+ ) {}
303+
304+ /* testClosureParamListWithTrailingComma */
305+ function (
306+ $ foo ,
307+ $ bar ,
308+ ) {};
309+
310+ /* testArrowFunctionParamListWithTrailingComma */
311+ $ fn = fn ( ?int $ a , ...$ b , ) => $ b ;
312+
313+ /* testClosureUseWithTrailingComma */
314+ function () use (
315+ $ foo /*comment*/ ,
316+ $ bar ,
317+ ) {};
318+
319+ /* testArrowFunctionLiveCoding */
320+ // Intentional parse error. This has to be the last test in the file.
321+ $ fn = fn
0 commit comments