-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Variadic parameters in PHP8 can have int|string key
- Loading branch information
Showing
9 changed files
with
207 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Bug2600; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doFoo($x = null) { | ||
$args = func_get_args(); | ||
assertType('mixed', $x); | ||
assertType('array', $args); | ||
} | ||
|
||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doBar($x = null) { | ||
assertType('mixed', $x); | ||
} | ||
|
||
/** | ||
* @param mixed $x | ||
*/ | ||
public function doBaz(...$x) { | ||
assertType('array<int|string, mixed>', $x); | ||
} | ||
|
||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doLorem(...$x) { | ||
assertType('array<int|string, mixed>', $x); | ||
} | ||
|
||
public function doIpsum($x = null) { | ||
$args = func_get_args(); | ||
assertType('mixed', $x); | ||
assertType('array', $args); | ||
} | ||
} | ||
|
||
class Bar | ||
{ | ||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doFoo($x = null) { | ||
$args = func_get_args(); | ||
assertType('string|null', $x); | ||
assertType('array', $args); | ||
} | ||
|
||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doBar($x = null) { | ||
assertType('string|null', $x); | ||
} | ||
|
||
/** | ||
* @param string $x | ||
*/ | ||
public function doBaz(...$x) { | ||
assertType('array<int|string, string>', $x); | ||
} | ||
|
||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doLorem(...$x) { | ||
assertType('array<int|string, string>', $x); | ||
} | ||
} | ||
|
||
function foo($x, string ...$y): void | ||
{ | ||
assertType('mixed', $x); | ||
assertType('array<int|string, string>', $y); | ||
} | ||
|
||
function ($x, string ...$y): void { | ||
assertType('mixed', $x); | ||
assertType('array<int|string, string>', $y); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php // lint >= 7.4 | ||
|
||
namespace Bug4902; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template T-wrapper | ||
*/ | ||
class Wrapper { | ||
/** @var T-wrapper */ | ||
public $value; | ||
|
||
/** | ||
* @param T-wrapper $value | ||
*/ | ||
public function __construct($value) { | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @template T-unwrap | ||
* @param Wrapper<T-unwrap> $wrapper | ||
* @return T-unwrap | ||
*/ | ||
function unwrap(Wrapper $wrapper) { | ||
return $wrapper->value; | ||
} | ||
|
||
/** | ||
* @template T-wrap | ||
* @param T-wrap $value | ||
* | ||
* @return Wrapper<T-wrap> | ||
*/ | ||
function wrap($value): Wrapper | ||
{ | ||
return new Wrapper($value); | ||
} | ||
|
||
|
||
/** | ||
* @template T-all | ||
* @param Wrapper<T-all> ...$wrappers | ||
*/ | ||
function unwrapAllAndWrapAgain(Wrapper ...$wrappers): void { | ||
assertType('array<int|string, T-all (method Bug4902\Wrapper::unwrapAllAndWrapAgain(), argument)>', array_map(function (Wrapper $item) { | ||
return $this->unwrap($item); | ||
}, $wrappers)); | ||
assertType('array<int|string, T-all (method Bug4902\Wrapper::unwrapAllAndWrapAgain(), argument)>', array_map(fn (Wrapper $item) => $this->unwrap($item), $wrappers)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace VariadicParameterPHP8; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function foo(...$args) | ||
{ | ||
assertType('array<int|string, mixed>', $args); | ||
assertType('mixed', $args['foo']); | ||
assertType('mixed', $args['bar']); | ||
} | ||
|
||
function bar(string ...$args) | ||
{ | ||
assertType('array<int|string, string>', $args); | ||
} | ||
|