4
3

More than 3 years have passed since last update.

include_pathについて整理

Last updated at Posted at 2020-04-09

include_pathとは

  • require()、include()、fopen()、file_get_contents()などのPHPのファイルを読み込む関数がファイルを検索するディレクトリのこと。
  • php.iniに設定しておくことでフルパスや相対パスで指定しなくても読み込める。
  • 「環境変数PATHに通す」のと似たような感じ

相対パスを指定した時の優先度

  • ※include(),require()関数しか調べてません
  • パスを指定しない場合
    • まずinclude_pathから探す
    • 無ければスクリプトと同ディレクトリから探す
  • 相対パスあるいは絶対パスを指定した場合
    • まずスクリプトと同ディレクトリから探す
    • 無ければinclude_path

コマンドラインでinclude_pathの設定を確認したいとき

php -r 'echo get_include_path() . "\n";'

参考

http://engineer-memo.goodhead.work/pages/212#title_415
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11189406816
https://jutememo.blogspot.com/2008/04/php-include.html

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