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

Fix reading/getting env vars #2

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

nlemoine
Copy link
Contributor

@nlemoine nlemoine commented Sep 9, 2024

@voronkovich
Copy link
Member

@nlemoine, I think we should keep getenv() as a fallback, because $_ENV could be disabled with variables_order directive:

; php.ini
variables_order = "GPCS"
$value = $_ENV[$key] ?? getenv($key);

@voronkovich
Copy link
Member

I just checked an official php.ini-production. The $_ENV is disabled by default. So I think it's better to use $_SERVER variable instead.

@nlemoine
Copy link
Contributor Author

nlemoine commented Sep 10, 2024

Hello @voronkovich,

Thanks you for the prompt feedback!

I just checked an official php.ini-production.

Interesting! However, $_ENV is still widely used and I think I never stumble on a server with E disabled.

Dotenv libraries usually populate both $_SERVER and $_ENV.

I updated the code to read from: $_SERVER, $_ENV, getenv, in that order:

$value = $_SERVER[$key] ?? $_ENV[$key] ?? getenv($key) !== false ?: null;

Checking if E is disabled with ini_get('variable_order') seems overkill IMHO.

Let me know if this looks right to you.

@voronkovich voronkovich merged commit 827e653 into PopArtDesign:main Sep 10, 2024
1 check passed
@voronkovich
Copy link
Member

@nlemoine, thanks for the contribution!

@nlemoine
Copy link
Contributor Author

Thanks for considering it!

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

Successfully merging this pull request may close these issues.

2 participants