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

sr57's avatar
Level 39

Where to put global constants?

What's the (best) place to put php constants used in all a project?

0 likes
4 replies
Tray2's avatar

I'd go with the .env file unless of course there are a shit load of them.

sr57's avatar
Level 39

Thanks for your answer @tray2

I would not like to modify my .env file, anyway to put it in a php file and have this file 'automatically' included for all scripts?

Snapey's avatar
Snapey
Best Answer
Level 122

If you need to change these constants between different deployments then use .env

Otherwise put them in a config file. All you need to do is create a php file in the config folder and in that file return an array.

You can then use these anywhere in your code with the config helper

sr57's avatar
Level 39

Thanks @snapey I didn't know that I can add a config file so easily.

Please or to participate in this conversation.