AbstractVariables::set( string $name, string|null $value = null )

Set an environment variable.


Parameters

$name

(string) (Required)

$value

(string|null) (Optional)

Default value: null


Return

(void)


Source

File: vendor/vlucas/phpdotenv/src/Environment/AbstractVariables.php

    public function set($name, $value = null)
    {
        if (!is_string($name)) {
            throw new InvalidArgumentException('Expected name to be a string.');
        }

        // Don't overwrite existing environment variables if we're immutable
        // Ruby's dotenv does this with `ENV[key] ||= value`.
        if ($this->isImmutable() && $this->get($name) !== null && $this->loaded->get($name)->isEmpty()) {
            return;
        }

        $this->setInternal($name, $value);
        $this->loaded->set($name, '');
    }