LoginSignup
0

More than 1 year has passed since last update.

include系とrequire系の使い分け

Last updated at Posted at 2022-09-04

include系とrequire系の違い

  • 結論
    ファイルの読み込みが失敗した場合の動作に違いがある

■使用例

include 'samplefile.php';
require 'samplefile.php';

include系の場合

指定したファイルの読み込みが失敗しても
Warning(警告)だけ表示され,処理が中断されない。
HTMLやテキスト等を読み込むときに使われる。

require系の場合

指定したファイルの読み込みが失敗した場合,
Fatal Error(致命的なエラー)が表示され,処理が中断される。
主に関数(メソッド)や処理を読み込む時に使われる。

参考記事

https://www.php.net/manual/ja/function.require.php
https://www.php.net/manual/ja/function.include.php

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