Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

toddmcbrearty's avatar

Best place to include a file

I'd like to add a file that just has functions available. Where is the best place to include this? start.php or global.php?

0 likes
10 replies
ax3lst's avatar

I think you can put it wherever you want. You only have to autoload it in you composer file.
You have to put this in the autoload section.

"files": ["path/to/yourfile.php"],
2 likes
anchour's avatar
anchour
Best Answer
Level 4

Autoload it in your composer.json.

"autoload": {
  "classmap": [
   "app/commands",
   "app/controllers",
   "app/models",
   "app/database/migrations",
   "app/database/seeds",
   "app/tests/TestCase.php"
  ],
  "files": [
    "app/helpers.php"
  ]
}

Edit: Damn, ax3l beat me to it! haha. Basically add whatever filepath it is to your "files" array in composer.json.

4 likes
JeffreyWay's avatar

Yeah - for things like that, I do the same as @mrobit. Add a files array to the autoload section of your composer.json file. That'll do the trick.

3 likes
toddmcbrearty's avatar

Don't know why I didn't think of that. Overthinking stinks! Thanks a lot.

mrterryh's avatar

You can also put it in app/start/global.php where Laravel includes the filters file.

isimmons's avatar

I like things to be in a single standard place so I chose to always use composer.json unless I have a service provider. You can require files in the boot method of a service provider but no need to make one if that is the only reason for it. For some reason I don't like using the start or global files for anything.

bagwaa's avatar

I just try and stick to using PSR-4 and if I need anything special I will just stick it in composer.json ...

Please or to participate in this conversation.