Why include __DIR__ in the require_once?

后端 未结 2 1395
旧时难觅i
旧时难觅i 2020-12-30 01:18

For example, I always see autoloaders called like this:

require_once __DIR__ . \'/../vendor/autoload.php\';

What is the difference between

2条回答
  •  忘掉有多难
    2020-12-30 01:21

    For include its possible to set some folders where PHP search automatically. When you include a file with a relative path you search in all of that folders. Its better to define the real path to prevent some errors in loading wrong files.

    https://secure.php.net/manual/en/function.set-include-path.php

    Then you can be sure that you load the correct file.

提交回复
热议问题