getenv

FunctionParams and return types changed in PHP 8.0

Gets the value of a single or all environment variables.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

getenv Function synopsis

getenv(?string $name = null, bool $local_only = false): array|string|false

Parameters

$name

OptionalType?stringDefault valuenull

The variable name as a string or null.

$local_only

OptionalTypeboolDefault valuefalse

When set to true, only local environment variables are returned, set by the operating system or putenv. It only has an effect when $name is a string.

Return value

Typearray|string|false

Returns the value of the environment variable $name, or false if the environment variable $name does not exist. If $name is null, all environment variables are returned as an associative array.

Changes to the getenv Function

PHP 8.0

  • Return type added: array|string|false
  • Parameter name of parameter #1 changed: $varname to $name
  • Parameter type added for parameter #1 ($name): ?string
  • Parameter default value added for position #1 ($name): null
  • Parameter type added for parameter #2 ($local_only): bool
  • Parameter default value added for position #2 ($local_only): false
- getenv($varname, $local_only)
+ getenv(?string $name = null, bool $local_only = false): array|string|false

PHP 5.6

  • Optional parameter added - #2: $local_only
- getenv($varname)
+ getenv($varname, $local_only)

getenv Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes