Skip to content

Instantly share code, notes, and snippets.

@o0h
Created February 24, 2021 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o0h/8f7e032f66a289520997d92a64e07781 to your computer and use it in GitHub Desktop.
Save o0h/8f7e032f66a289520997d92a64e07781 to your computer and use it in GitHub Desktop.
PHPStanのmatch式解析がよく分からん・・?
<?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'
};
}
| Line | Error |
| --- | --- |
|9 | Match expression does not handle remaining value: mixed |
<?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