Slide 34
Slide 34 text
PHPStan(Larastan) の罠
/**
* @return array
*/
function state1(): array
{
return [
'name' => 'name',
'age' => 17,
'isActive' => true,
];
}
/**
* @return array{name: string, age: int, isActive: bool}
*/
function state2(): array
{
return [
'name' => 'name',
'age' => 17,
'isActive' => true,
];
}
/**
* @return array // 怒られない(まぁ分かる)
*/
function state3(): array
{
return [
'name' => 'name',
'age' => 17,
'isActive' => true,
'sex' => 1,
];
}
/**
* @return array{name: string, age: int, isActive: bool} // 怒られない!?
*/
function state4(): array
{
return [
'name' => 'name',
'age' => 17,
'isActive' => true,
'sex' => 1,
];
}