Home
DevCentral
Search
Configure Global Search
Log In
Transactions
D2497
Change Details
Change Details
Old
New
Diff
By default, Fedora and Ubuntu PHP packages maintainers set the variables_order configuration variable to GPCS, not filling the $_ENV array. The Environment class provides a standard way to query both $_ENV and $_SERVER. Advantage against getenv() is it doesn't return false if the value doesn't exist, but throw an exception. The getOr variable allows to provide a default value, so $_ENV['foo'] ?? $_SERVER['foo'] ?? default can be expressed more easily. References: - https://www.php.net/manual/en/ini.core.php - https://www.php.net/manual/en/install.fpm.configuration.php
The Environment class provides a standard way to query both `$_ENV` and `$_SERVER`. Advantage against `getenv()` is it doesn't return false if the value doesn't exist, but throw an exception. The `getOr` method allows to provide a default value, so `$_ENV['foo'] ?? $_SERVER['foo'] ?? default can` be expressed a more compact way. This is intended to allow applications to fetch environment and be sure to get the environment variable as an answer. **$_ENV and $_SERVER for environment** PHP allows to control the order of superglobals array, like $_SERVER and $_ENV, but also to restrain to set one. When software is configured through environment variables, this situation creates a tricky situation: - The default PHP value is EGPCS, so we've $_ENV - The suggested production config is GPCS, without $_ENV By default, Fedora and Ubuntu PHP packages maintainers set the variables_order configuration variable to GPCS, not filling the $_ENV array. Meanwhile, any variable defined through php-fpm environment will be filled in $_SERVER. $_SERVER would also receive the php-fpm process environment if clean_env is set to false. As far as a generic application is concerned, this situation means any environment variable could be set in $_ENV, $_SERVER or both. In PHP core, the getenv() method read both arrays. **References** - https://www.php.net/manual/en/ini.core.php - https://www.php.net/manual/en/install.fpm.configuration.php
The Environment class provides a standard way to query both `$_ENV` and `$_SERVER`. Advantage against `getenv()` is it doesn't return false if the value doesn't exist, but throw an exception. The `getOr` method allows to provide a default value, so `$_ENV['foo'] ?? $_SERVER['foo'] ?? default can` be expressed a more compact way. This is intended to allow applications to fetch environment and be sure to get the environment variable as an answer. **$_ENV and $_SERVER for environment** PHP allows to control the order of superglobals array, like $_SERVER and $_ENV, but also to restrain to set one. When software is configured through environment variables, this situation creates a tricky situation: - The default PHP value is EGPCS, so we've $_ENV - The suggested production config is GPCS, without $_ENV
By default, Fedora and Ubuntu PHP packages maintainers set the variables_order configuration variable to GPCS, not filling the $_ENV array.
The Environment class provides a standard way to query both
Meanwhile, any variable defined through php-fpm environment
$_ENV and
will be filled in
$_SERVER.
Advantage against getenv() is it doesn't
$_SERVER would also receive the
return false if the value doesn't exist, but throw an exception
php-fpm process environment if clean_env is set to false
.
The getOr variable allows to provide a default value
As far as a generic application is concerned
,
so
this situation
$_ENV['foo'] ?? $_SERVER['foo'] ??
means any environment variable could be set in $_ENV,
default can be expressed
$_SERVER
more easily
or both. In PHP core, the getenv() method read both arrays
.
**
References
:
**
- https://www.php.net/manual/en/ini.core.php - https://www.php.net/manual/en/install.fpm.configuration.php
Continue