- Laravel Version: 8.54.0
- PHP Version: 7.4.14
- Database Driver & Version: Mysql / 8.0.23
The Problem
A composer package my app requires uses $_ENV to access env vars. I'm using a class from this package in a listener that is registered in EventServiceProvider in the $listen property. The $_ENV values are not set. The $_ENV variables are correctly loaded from .env everywhere else. This package is not Laravel specific, so env() helper is not an option.
This issue, which is closed, mentions the same issue but, I thought getenv is discouraged and should be avoided being it is not thread safe.
Steps To Reproduce:
- Register a listener in EventServiceProvider@$listen
// EventServiceProvider.php
protected $listen = [
\App\Events\FooEvent::class => [
\App\Listeners\FooListener::class,
],
];
- In FooListener::class, call $_ENV['FOO'];