You can parse an .env file as an .ini with PHP - but there's a catch (shkspr.mobi)
from mesamunefire@piefed.social to programming@programming.dev on 26 Apr 03:49
https://piefed.social/c/programming/p/2012799/you-can-parse-an-env-file-as-an-ini-with-php-but-there-s-a-catch

The humble .env file is a useful and low-tech way of storing persistent environment variables. Drop the file on your server and let your PHP scripts consume it with glee. But consume it how? There are lots of excellent parsing libraries for PHP. But isn’t there a simpler way? Yes! You can use PHP’s parse_ini_file() function and it works. But… .env and .ini have subtly different behaviour which …

#programming

threaded - newest

nous@programming.dev on 26 Apr 12:01 next collapse

If you can drop a .env file on a server. You can drop a well formed .ini file instead. I don’t see any reason to ever parse a env file as a ini file.

bitfucker@programming.dev on 27 Apr 05:08 collapse

Also I don’t understand why we need to have a .env file in the first place when config file exists and best practice to pass on secret is not with .env file anyway.

luciole@beehaw.org on 27 Apr 01:41 collapse

TLDR:

You should probably use a proper parser rather than hoping your .env looks enough like an .ini to pass muster.

You can probably use a butter knife instead of a flat screwdriver but just do your job properly.