HomeDevCentral

WIP: EGPCS vs GPCS for environment

Description

WIP: EGPCS vs GPCS for environment

Summary:
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

Test Plan: Units tests covering all methods.

Reviewers: dereckson

Reviewed By: dereckson

Differential Revision: https://devcentral.nasqueron.org/D2497

Details

Provenance
derecksonAuthored on Feb 5 2022, 03:57
derecksonPushed on Feb 5 2022, 12:14
Reviewer
dereckson
Differential Revision
D2497: Read from environment when PHP doesn't populate $_ENV
Parents
rKOTf1b282e7562c: Don't allow to construct a File with a null path
Branches
Unknown
Tags
Unknown
References
tag: 0.5.0