Dotenv not working

I’m in the process of upgrading my Checkout API code from V1 to V2. Things seem to be going well, except that (of all things) Dotenv has decided to misbehave. In my sandbox (local) environment, I’ve verified that the path is correct and my .env file exists, but Dotenv::create() quits silently. I can’t use a try/catch, because all the possible exceptions have been short-circuited in the Dotenv source code - the module is built to die silently, in other words.

I know this isn’t quite Square territory, but any help would be appreciated. Thanks!

Problem solved: my code had something of the form
use Dotenv\Dotenv; ... Dotenv::create(__DIR__);
when the correct syntax is
Dotenv\Dotenv::createImmutable(__DIR__);

The use isn’t usefule in this case. Also, create() isn’t supported by itself anymore - you need to call an implementation like createImmutable(),

1 Like