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

feat: add support for using $_ENV instead of getenv/putenv #432

Open
bshaffer opened this issue Jan 25, 2023 · 2 comments
Open

feat: add support for using $_ENV instead of getenv/putenv #432

bshaffer opened this issue Jan 25, 2023 · 2 comments
Labels
lang: php Issues specific to PHP. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@bshaffer
Copy link
Contributor

bshaffer commented Jan 25, 2023

getenv and putenv are considered not threadsafe. As a result,
We should expose a way (similar to symphony's usePutenv function) to use the threadsafe version ($_ENV) instead.

As @DracoBlue mentioned in #429:

The current version of google auth library php uses getenv/putenv to read and set environment variables in php. But the function putenv is not threadsafe, which made libraries (Dotenv https://github.com/symfony/dotenv/blob/6.2/Dotenv.php#L61 and phpdotenv https://github.com/vlucas/phpdotenv#putenv-and-getenv) to disable putenv support by default. Frameworks like symfony (deprecated in 4.3 symfony/symfony#31062 and removed in 5.0) and also in laravel there was a similiar solution to not use it anymore directly (vlucas/phpdotenv#76).

Thus here is a pull request to change all the ocurences of:

  • getenv($variable) to array_key_exists($variable, $_ENV) ? $_ENV[$variable] : false
  • putenv($variable) to unset($_ENV[$variable])
  • putenv($variable . "=") to $_ENV[$variable]=''
  • putenv($variable . "=" . $value) to $_ENV[$variable]=$value

Threads about this:

@DracoBlue
Copy link

Thanks for creating the feature request!

@yash30201 yash30201 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. lang: php Issues specific to PHP. labels Mar 7, 2023
@faizanakram99
Copy link

Isn't this change safe and non BC?

-        $path = getenv(self::ENV_VAR);
+        $path = getenv(self::ENV_VAR) ?: $_ENV[self::ENV_VAR] ?: $_SERVER[self::ENV_VAR];

here

$path = getenv(self::ENV_VAR);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: php Issues specific to PHP. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants