LoginSignup
0
0

More than 1 year has passed since last update.

【PHP】nullableな型

Posted at

環境

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 

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0