Download the PHP package julienlinard/php-dotenv without Composer
On this page you can find all versions of the php package julienlinard/php-dotenv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download julienlinard/php-dotenv
More information about julienlinard/php-dotenv
Files in julienlinard/php-dotenv
Package php-dotenv
Short Description Une librairie PHP simple et moderne pour charger les variables d'environnement depuis un fichier .env
License MIT
Homepage https://github.com/julien-lin/php-dotenv
Informations about the package php-dotenv
PHP Dotenv
๐ฌ๐ง Read in English
๐ Support the project
If this bundle is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
A simple and modern PHP library for loading environment variables from a .env file.
๐ Installation
Requirements: PHP 8.0 or higher
โก Quick Start
๐ Features
- โ
.envfile loading - โ
Comment support (lines starting with
#) - โ Support for single and double quoted values
- โ Multi-line value support
- โ
Variable expansion (
${VAR}or$VAR) - โ Immutable mode (does not replace existing variables)
- โ Required variable validation
- โ Boolean and null value support
๐ Usage
Basic Loading
Mutable Loading
Required Variable Validation
Validation with Default Values
Direct Variable Retrieval
๐ .env File Format
๐ Security
- Variables are loaded into
$_ENVand$_SERVER - Immutable mode by default (does not replace existing system variables)
- Variable name validation (alphanumeric characters and underscores only)
๐ Integration with Other Packages
Integration with core-php
core-php automatically includes php-dotenv. Use loadEnv() to load variables.
Standalone Usage
php-dotenv can be used independently of all other packages.
Usage with Other Frameworks
๐ API Reference
Dotenv::createImmutable(string $path, string $file = '.env'): Dotenv
Creates an immutable instance that does not replace existing variables.
Dotenv::createMutable(string $path, string $file = '.env'): Dotenv
Creates a mutable instance that replaces existing variables.
load(): void
Loads the .env file and sets environment variables in $_ENV and $_SERVER.
required(array $variables): Validator
Validates that the specified variables exist. Throws an exception if a variable is missing.
get(string $key, mixed $default = null): mixed
Retrieves a variable with an optional default value.
๐ก Advanced Usage Examples
Validation with Default Values
Conditional Loading
Usage in a CLI Script
๐งช Tests
๐ License
MIT License - See the LICENSE file for more details.
๐ค Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
๐ Support the project
If this bundle is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
Developed with โค๏ธ by Julien Linard