LoginSignup
16
4

More than 3 years have passed since last update.

PHPStormのTemplateを設定してdeclare(strict_types=1)を常に設定する

Posted at

PHPStormのTemplateを設定してdeclare(strict_types=1)を常に設定する

PHP7からdeclare(strict_types=1)が導入され、設定している場合は暗黙的な型変換が行われなくなり、より厳密にタイプヒンティングをチェックするようにできます。

しかしdeclare(strict_types=1)はファイル単位でしか効力が無いため、常にファイルの冒頭に書かなければいけません。

これを矯正するためにPHPStormに設定を追加します。

スクリーンショット 2020-01-24 18.38.47.png

PHPStormのCode Templatesを利用します。

Preferences > Editor > File and Code TemplatesでPHPを選択し、テンプレートの初めにdeclare(strict_types=1)を追記しましょう。

これでPHPファイルを作成するときに自動的にdeclare(strict_types=1)が追加されます。

16
4
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
16
4