include vendor/autoload.php automatically
| From: | Abdul Haq Sheikh | Date: | Sat, 27 Mar 2021 16:52:38 +0000 |
| Subject: | include vendor/autoload.php automatically | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-113813@lists.php.net to get a copy of this message | ||
If we want to use composer packages, we have to include
'vendor/autoload.php', and if we don't have a front controller design
pattern, we must include 'vendor/autoload.php' on every/most files. Why not
to auto include 'vendor/autoload.php' file (if vendor folder exists)?
* PHP will use include_once to include file
Example Directory Structure:
- Index.php (file)
- Test.php (file)
- Classes (folder)
-- Classes/test2.php (file)
- Vendor (folder)
- On Index.php, php will automatically include 'vendor/autoload.php'
because the vendor directory exists.
- On Test.php, php will automatically include 'vendor/autoload.php'
because the vendor directory exists.
- On Classes/test2.php, since file is in sub directory and here vendor
directory doesn't exist, so php will not include 'vendor/autoload.php'