Skip to content

Upgrading vlucas/phpdotenv 2 to 3

Breakingv2.6.9 → v3.6.10Breaking4New8Changed5Fixed14Other3

BreakingUpgrade verdict

4 breaking changes.

  • Spaces around values are kept now, so code expecting trimmed values may need updating.
  • Spaces around values are no longer removed, so values come back exactly as written in the file.
  • You now create the loader with a static factory method instead of the constructor.
  • Loading now gives you a map of variable names to values instead of the raw file lines.
Top 3 of 4 that need code or config changes

vlucas/phpdotenv publishes an official migration guide for version 3. It covers more than the release notes do.

Upgrading guide ↗

PHP requirement changed in v3.6.4: ^5.3.9 || ^7.0 || ^8.0 → ^5.4 || ^7.0 || ^8.0.

Breaking4
Values are no longer trimmed, which may break callers relying on trimmed values.
Stops trimming values; values are now returned exactly as written.
Replaces the new Dotenv(...) constructor with the static Dotenv::create(...) factory.
Dotenv::create()
Loader::load() and its callers now return an associative array of loaded variables and values instead of raw lines.
Loader::load()

Generated by DepDelta from published PHP source. Not mixed with prose notes.

  • removed: method Loader.getImmutable()
  • removed: method Loader.processFilters($name, $value)
  • removed: protected method Dotenv.getFilePath($path, $file)
  • removed: protected method Loader.ensureFileIsReadable()
  • removed: protected method Loader.isComment($line)
  • removed: protected method Loader.looksLikeSetter($line)
  • removed: protected method Loader.normaliseEnvironmentVariable($name, $value)
  • removed: protected method Loader.readLinesFromFile($filePath)
  • removed: protected method Loader.resolveNestedVariables($value)
  • removed: protected method Loader.sanitiseVariableName($name, $value)
  • removed: protected method Loader.sanitiseVariableValue($name, $value)
  • removed: protected method Loader.splitCompoundStringIntoParts($name, $value)
  • removed: protected property Dotenv.filePath
  • removed: protected property Loader.filePath
  • removed: protected property Loader.immutable
  • removed: static method Parser.parseName($name)
  • removed: static method Parser.parseQuotedValue($value)
  • removed: static method Parser.parseUnquotedValue($value)
  • removed: static method Parser.parseValue($value)
  • changed: constructor Dotenv($path, $file = …) → constructor Dotenv(Loader $loader)
  • changed: constructor Loader($filePath, $immutable = …) → constructor Loader(array $filePaths, FactoryInterface $envFactory, $immutable = …)
  • changed: constructor Validator(array $variables, Loader $loader) → constructor Validator(array $variables, Loader $loader, $required = …)
  • changed: method Dotenv.required($variable) → method Dotenv.required($variables)
  • changed: property Loader.variableNames → protected property Loader.variableNames
  • changed: protected method Validator.assertCallback($callback, $message = …) → protected method Validator.assertCallback(callable $callback, $message = …)
  • added: class Lines
  • added: const Parser.UNQUOTED_STATE
  • added: method Dotenv.ifPresent($variables)
  • added: method Loader.getEnvironmentVariableNames()
  • added: method Loader.loadDirect($content)
  • added: method Validator.allowedRegexValues($regex)
  • added: protected property Loader.envFactory
  • added: protected property Loader.envVariables
  • added: protected property Loader.filePaths
  • added: static method Dotenv.create($paths, $file = …, FactoryInterface $envFactory = …)
  • added: static method Lines.process(array $lines)
  • added: static method Parser.parse($entry)
  • added: abstract class AbstractVariables implements VariablesInterface
  • added: class DotenvFactory implements FactoryInterface
  • added: class DotenvVariables extends AbstractVariables
  • added: constructor AbstractVariables($immutable)
  • added: constructor DotenvFactory(array $adapters = …)
  • added: constructor DotenvVariables(array $adapters, $immutable)
  • added: interface FactoryInterface
  • added: interface VariablesInterface extends ArrayAccess
  • added: method AbstractVariables.clear($name)
  • added: method AbstractVariables.get($name)
  • added: method AbstractVariables.has($name)
  • added: method AbstractVariables.isImmutable()
  • added: method AbstractVariables.offsetExists($offset)
  • added: method AbstractVariables.offsetGet($offset)
  • added: method AbstractVariables.offsetSet($offset, $value)
  • added: method AbstractVariables.offsetUnset($offset)
  • added: method AbstractVariables.set($name, $value = …)
  • added: method DotenvFactory.create()
  • added: method DotenvFactory.createImmutable()
  • added: method FactoryInterface.create()
  • added: method FactoryInterface.createImmutable()
  • added: method VariablesInterface.clear($name)
  • added: method VariablesInterface.get($name)
  • added: method VariablesInterface.has($name)
  • added: method VariablesInterface.isImmutable()
  • added: method VariablesInterface.set($name, $value = …)
  • added: protected method AbstractVariables.clearInternal($name)
  • added: protected method AbstractVariables.getInternal($name)
  • added: protected method AbstractVariables.setInternal($name, $value = …)
  • added: protected method DotenvVariables.clearInternal($name)
  • added: protected method DotenvVariables.getInternal($name)
  • added: protected method DotenvVariables.setInternal($name, $value = …)
  • added: protected property DotenvFactory.adapters
  • added: protected property DotenvVariables.adapters
  • added: class ApacheAdapter implements AdapterInterface
  • added: class ArrayAdapter implements AdapterInterface
  • added: class EnvConstAdapter implements AdapterInterface
  • added: class PutenvAdapter implements AdapterInterface
  • added: class ServerConstAdapter implements AdapterInterface
  • added: interface AdapterInterface
  • added: method AdapterInterface.clear($name)
  • added: method AdapterInterface.get($name)
  • added: method AdapterInterface.isSupported()
  • added: method AdapterInterface.set($name, $value = …)
  • added: method ApacheAdapter.clear($name)
  • added: method ApacheAdapter.get($name)
  • added: method ApacheAdapter.isSupported()
  • added: method ApacheAdapter.set($name, $value = …)
  • added: method ArrayAdapter.clear($name)
  • added: method ArrayAdapter.get($name)
  • added: method ArrayAdapter.isSupported()
  • added: method ArrayAdapter.set($name, $value = …)
  • added: method EnvConstAdapter.clear($name)
  • added: method EnvConstAdapter.get($name)
  • added: method EnvConstAdapter.isSupported()
  • added: method EnvConstAdapter.set($name, $value = …)
  • added: method PutenvAdapter.clear($name)
  • added: method PutenvAdapter.get($name)
  • added: method PutenvAdapter.isSupported()
  • added: method PutenvAdapter.set($name, $value = …)
  • added: method ServerConstAdapter.clear($name)
  • added: method ServerConstAdapter.get($name)
  • added: method ServerConstAdapter.isSupported()
  • added: method ServerConstAdapter.set($name, $value = …)
  • removed: class InvalidCallbackException extends InvalidArgumentException implements ExceptionInterface
  • added: abstract class Result
  • added: class Error extends Result
  • added: class Regex
  • added: class Success extends Result
  • added: method Error.error()
  • added: method Error.mapError(callable $f)
  • added: method Error.mapSuccess(callable $f)
  • added: method Error.success()
  • added: method Result.error()
  • added: method Result.getError()
  • added: method Result.getSuccess()
  • added: method Result.mapError(callable $f)
  • added: method Result.mapSuccess(callable $f)
  • added: method Result.success()
  • added: method Success.error()
  • added: method Success.mapError(callable $f)
  • added: method Success.mapSuccess(callable $f)
  • added: method Success.success()
  • added: static method Error.create($value)
  • added: static method Regex.match($pattern, $subject)
  • added: static method Regex.replace($pattern, $replacement, $subject)
  • added: static method Regex.replaceCallback($pattern, callable $callback, $subject)
  • added: static method Success.create($value)