Dotenv\Loader::clearEnvironmentVariable PHP Method

clearEnvironmentVariable() public method

This is not (currently) used by Dotenv but is provided as a utility method for 3rd party code. This is done using: - putenv, - unset($_ENV, $_SERVER).
See also: setEnvironmentVariable()
public clearEnvironmentVariable ( string $name ) : void
$name string
return void
    public function clearEnvironmentVariable($name)
    {
        // Don't clear anything if we're immutable.
        if ($this->immutable) {
            return;
        }
        if (function_exists('putenv')) {
            putenv($name);
        }
        unset($_ENV[$name], $_SERVER[$name]);
    }

Usage Example

Example #1
0
 /**
  * @override
  * @inheritDoc
  */
 public function clearEnvironmentVariable($name)
 {
     if (strpos($name, 'INI_') === 0) {
         $normalized = str_replace('INI_', '', $name);
         $normalized = strtolower($normalized);
         $this->invoker->call('ini_restore', [$normalized]);
     }
     parent::clearEnvironmentVariable($name);
 }