Created
February 24, 2021 08:11
-
-
Save o0h/8f7e032f66a289520997d92a64e07781 to your computer and use it in GitHub Desktop.
PHPStanのmatch式解析がよく分からん・・?
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
<?php declare(strict_types = 1); | |
// https://phpstan.org/r/08461790-ec36-4043-8fd4-0c11074d44ea | |
/** | |
* @param mixed $a some value | |
* @return mixed | |
*/ | |
function returnMatch($a): mixed | |
{ | |
return match ($a) { | |
'a' => 'a', | |
'x' => 'aaaa', | |
'z' => 'aaaaaaaa' | |
}; | |
} |
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
| Line | Error | | |
| --- | --- | | |
|9 | Match expression does not handle remaining value: mixed | |
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
<?php declare(strict_types = 1); | |
// https://3v4l.org/hMKio | |
/** | |
* @param mixed $a some value | |
* @return mixed | |
*/ | |
function returnMatch($a): mixed | |
{ | |
return match ($a) { | |
'a' => 'a', | |
'x' => 'aaaa', | |
'z' => 'aaaaaaaa' | |
}; | |
} | |
echo returnMatch('x'); // aaaa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment