環境
nullableな型
型宣言の前に?
をつけると、指定した型かnull
が許容される。
public static function createPostBy(
int $userId,
string $type,
string $content,
?DateTime $deletedAt
)
{
self::create([
...
]);
}
?
をつけずに引数にnull
を入れていると下記のようにエラーが出る。
Argument #2 ($deletedAt) must be of type int, null given, called in
参考