Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Env Laravel Package

php-standard-library/env

A lightweight PHP package from the Standard Library for inspecting and modifying environment variables, working directories, and filesystem paths, with simple, consistent functions that are easy to drop into any project.

View on GitHub
Deep Wiki
Context7

PHP Standard Library - Env provides a dependable set of functions for inspecting and modifying environment variables, the working directory, and filesystem paths in PHP. It offers a consistent, dependency-free API that behaves predictably across platforms, making configuration handling and path manipulation safer than relying on raw superglobals or scattered native calls.

  • Read, write, and remove environment variables through a uniform interface
  • Detect and change the current working directory
  • Normalize, join, and resolve paths portably
  • Predictable behavior across operating systems
  • Part of the modular php-standard-library ecosystem
Frequently asked questions about Env
How do I install php-standard-library/env in a Laravel project?
Install it with Composer using composer require php-standard-library/env. The package ships a set of global helper functions that are autoloaded through Composer's files directive, so there is no service provider to register or config file to publish. Once installed you can call functions like envString and envInt anywhere in your application, including queue workers and CLI commands.
Does php-standard-library/env work with Laravel's env() helper and cached configuration?
It complements Laravel rather than replacing it. Laravel's config() repository is cached and should stay the primary source for the web layer, while these helpers read the live process environment at call time. That makes them a good fit for non-web layers such as queues, scheduled jobs, and shared libraries where cached configuration is unavailable or stale.
What helper functions does php-standard-library/env provide?
The package provides typed readers for environment variables that return consistent types with sensible defaults, along with helpers for inspecting and modifying the working directory and resolving file paths. The typed accessors avoid the stringly-typed results you get from raw getenv(). This keeps environment handling uniform across scripts, libraries, and services.
Can I use php-standard-library/env outside of Laravel?
Yes, the package is framework-agnostic and has no hard dependencies beyond PHP core. It works in Symfony applications, PSR-15 middleware, plain PHP scripts, and CI/CD deployment tooling. The only requirement is that environment variables are already populated in the process before you read them.
Does php-standard-library/env load .env files automatically?
No. The package only inspects and modifies variables that already exist in the process environment, so it does not scan for or parse .env files. In Laravel, the framework's own bootstrap loader handles that, and in plain PHP you should pair the package with a loader such as vlucas/phpdotenv. It coexists with phpdotenv rather than replacing it.
How do I handle boolean environment variables safely?
Use envBool with an explicit default so you always receive a real boolean instead of a string such as "false" evaluating as truthy. Be aware that permissive parsing may treat values like "yes", "on", or "1" as true, so validate or normalize values that come from untrusted sources. For strict requirements, add your own validation rule around the helper rather than relying on implicit coercion.
How do I test code that uses php-standard-library/env?
Set the variables in the test process before invoking the code under test, using putenv or $_ENV in setUp, and reset them in tearDown to avoid leaking state between tests. Where the package supports explicit assignment, you can also override values directly inside the test. For the cleanest tests, inject the resolved values into your classes instead of calling the helpers deep inside business logic.
What are the performance considerations for high-throughput jobs or cron scripts?
Each call parses the current value, so in tight loops the overhead can add up even though individual calls are cheap. Read each variable once into a local variable or a small configuration object at the start of a job and reuse it. For API gateways and other hot paths, prefer cached configuration over repeated environment lookups.
What PHP versions and dependencies does php-standard-library/env require?
The package has no hard dependencies beyond PHP core itself, which keeps it lightweight and low risk to add. It is released under the MIT license, so there are no legal blockers for commercial use. Check the repository's composer.json for the exact minimum PHP version supported by the release you install.
How is php-standard-library/env different from getenv() or Laravel's env() helper?
Raw getenv() always returns a string or false, which leads to subtle bugs when comparing values like "true" or "0". These helpers return typed values with explicit defaults, giving you predictable behavior in queues, CLI tools, and shared libraries that cannot rely on Laravel's facades. Migrating is incremental: audit getenv() and $_ENV usage, replace one module at a time, then tighten type hints once the values are guaranteed.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle