File tree Expand file tree Collapse file tree 7 files changed +46
-1
lines changed
Standards/PSR12/Tests/Operators Expand file tree Collapse file tree 7 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,5 @@ $fn = fn(array &$one) => 1;
61
61
$ fn = fn (array & $ one ) => 1 ;
62
62
63
63
$ fn = static fn (DateTime $ a , DateTime $ b ): int => -($ a ->getTimestamp () <=> $ b ->getTimestamp ());
64
+
65
+ function issue3267 (string |int ...$ values ) {}
Original file line number Diff line number Diff line change @@ -61,3 +61,5 @@ $fn = fn(array &$one) => 1;
61
61
$fn = fn(array & $one) => 1;
62
62
63
63
$fn = static fn(DateTime $a, DateTime $b): int => -($a->getTimestamp() <=> $b->getTimestamp());
64
+
65
+ function issue3267(string|int ...$values) {}
Original file line number Diff line number Diff line change @@ -2540,7 +2540,6 @@ protected function processAdditional()
2540
2540
|| $ this ->tokens [$ x ]['code ' ] === T_ELLIPSIS )
2541
2541
) {
2542
2542
// Skip past reference and variadic indicators for parameter types.
2543
- ++$ x ;
2544
2543
continue ;
2545
2544
}
2546
2545
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ function namespaceOperatorTypeHint(?namespace\Name $var1) {}
45
45
/* testPHP8UnionTypesSimple */
46
46
function unionTypeSimple (int |float $ number , self |parent &...$ obj ) {}
47
47
48
+ /* testPHP8UnionTypesWithSpreadOperatorAndReference */
49
+ function globalFunctionWithSpreadAndReference (float |null &$ paramA , string |int ...$ paramB ) {}
50
+
48
51
/* testPHP8UnionTypesSimpleWithBitwiseOrInDefault */
49
52
$ fn = fn (int |float $ var = CONSTANT_A | CONSTANT_B ) => $ var ;
50
53
Original file line number Diff line number Diff line change @@ -370,6 +370,36 @@ public function testPHP8UnionTypesSimple()
370
370
}//end testPHP8UnionTypesSimple()
371
371
372
372
373
+ /**
374
+ * Verify recognition of PHP8 union type declaration when the variable has either a spread operator or a reference.
375
+ *
376
+ * @return void
377
+ */
378
+ public function testPHP8UnionTypesWithSpreadOperatorAndReference ()
379
+ {
380
+ $ expected = [];
381
+ $ expected [0 ] = [
382
+ 'name ' => '$paramA ' ,
383
+ 'content ' => 'float|null &$paramA ' ,
384
+ 'pass_by_reference ' => true ,
385
+ 'variable_length ' => false ,
386
+ 'type_hint ' => 'float|null ' ,
387
+ 'nullable_type ' => false ,
388
+ ];
389
+ $ expected [1 ] = [
390
+ 'name ' => '$paramB ' ,
391
+ 'content ' => 'string|int ...$paramB ' ,
392
+ 'pass_by_reference ' => false ,
393
+ 'variable_length ' => true ,
394
+ 'type_hint ' => 'string|int ' ,
395
+ 'nullable_type ' => false ,
396
+ ];
397
+
398
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
399
+
400
+ }//end testPHP8UnionTypesWithSpreadOperatorAndReference()
401
+
402
+
373
403
/**
374
404
* Verify recognition of PHP8 union type declaration with a bitwise or in the default value.
375
405
*
Original file line number Diff line number Diff line change @@ -48,6 +48,13 @@ class TypeUnion
48
48
/* testTypeUnionClosureParamIllegalNullable */
49
49
$ closureWithParamType = function (?string |null $ string ) {};
50
50
51
+ function globalFunctionWithSpreadAndReference (
52
+ /* testTypeUnionWithReference */
53
+ float |null &$ paramA ,
54
+ /* testTypeUnionWithSpreadOperator */
55
+ string |int ...$ paramB
56
+ ) {}
57
+
51
58
/* testBitwiseOrClosureParamDefault */
52
59
$ closureWithReturnType = function ($ string = NONSENSE | FAKE )/* testTypeUnionClosureReturn */ : \Package \MyA |PackageB {};
53
60
Original file line number Diff line number Diff line change @@ -110,6 +110,8 @@ public function dataTypeUnion()
110
110
['/* testTypeUnionAbstractMethodReturnType1 */ ' ],
111
111
['/* testTypeUnionAbstractMethodReturnType2 */ ' ],
112
112
['/* testTypeUnionClosureParamIllegalNullable */ ' ],
113
+ ['/* testTypeUnionWithReference */ ' ],
114
+ ['/* testTypeUnionWithSpreadOperator */ ' ],
113
115
['/* testTypeUnionClosureReturn */ ' ],
114
116
['/* testTypeUnionArrowParam */ ' ],
115
117
['/* testTypeUnionArrowReturnType */ ' ],
You can’t perform that action at this time.
0 commit comments