Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - are there any 'builtin' variables? #550

Closed
treii28 opened this issue Mar 17, 2023 · 5 comments
Closed

Question - are there any 'builtin' variables? #550

treii28 opened this issue Mar 17, 2023 · 5 comments

Comments

@treii28
Copy link

treii28 commented Mar 17, 2023

You give an example that shows setting a 'BASEDIR' then using it ( ${BASEDIR} ) in other variables. Since the .env file is usually placed in the root of a project or package, is there any means to access some kind of built-in that will tell you the directory/path where the .env is located to automagically set a BASEDIR or ROOTDIR using whatever location the .env file is stored?

@GrahamCampbell
Copy link
Collaborator

No, there are no built-ins, but there may be variables already set outside of your env file that can be access from it.

@GrahamCampbell
Copy link
Collaborator

Some that are resolved from $_SERVER: https://www.php.net/manual/en/reserved.variables.server.php.

@treii28
Copy link
Author

treii28 commented Mar 20, 2023

yeah, it will contain a PWD, but when I played with that one, it tells you the directory of the calling script, not the location of the .env file. I already had a method -- since the calling scripts are generally going to be 'under' the project root -- that will search-up the current path until it finds a .env (in my case, I also confirm with other directories/files such a vendor and composer). But that too can be unreliable as dev environments often use symlinks for local packages who's source code is under a different path.
I was just curious before hardcoding a parameter in every installations .env file. It just seems quirky to hard code a path that you then have to hard code again to read the environment file to get the path. And or to read an env file to set environment variables then have to set an environment variable of where you found the env file (or where root is). I thought maybe the path read might be stored somewhere.

@scottw-finao
Copy link

I'd still like to upvote this - it would still be nice to be able to get the directory where the .env file was located in other code after the environment was loaded. (I ran into another situation where this would be useful)

@justinskolnick
Copy link

You can save the path to a constant and pass it into Dotenv\Dotenv::createImmutable().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants