sebastian/environment
sebastian/environment helps PHP developers detect runtime details (PHP vs HHVM, OS, architecture, 32/64-bit, debugging extensions) to choose runtime-specific execution paths. Commonly used by testing tools to adapt behavior to the environment.
if (Runtime::isHhvm() && Runtime::getHhvmVersion() >= '4.0').if (defined('HHVM_VERSION')) blocks.Runtime::isOpcacheActive()).PHP_SAPI, HHVM_VERSION) when this package is maintained by the PHP ecosystem’s core contributors (Sebastian Bergmann) and used in PHPUnit.if (!Runtime::canCollectCodeCoverage()) $this->markTestSkipped()).Adopt if:
version_compare() or defined() checks.app()->environment() (e.g., OS-specific paths, PHP extension checks, or HHVM-specific behaviors).Look elsewhere if:
vlucas/phpdotenv or symfony/dotenv instead).jenssegers/agent or mobiledetectlib/mobile-detect.symfony/process or custom solutions.phpversion(), PHP_SAPI).For Executives: *"This package lets us write cleaner, more maintainable code by handling PHP/HHVM differences automatically—reducing bugs in mixed environments and future-proofing our stack. It’s a drop-in solution used by PHPUnit, so it’s battle-tested and won’t add technical debt. For example:
For Engineers:
*"The sebastian/environment package provides a clean abstraction for runtime checks (e.g., Environment::detect(), Runtime::isHhvm()). It’s perfect for:
if (version_compare(PHP_VERSION, '8.0.0') >= 0) with if (Environment::isPhp80()).Runtime::isHhvm().if (!Environment::isPhp81()) exit(1)).Why not use Laravel’s built-ins?
app()->environment() is great for high-level checks (e.g., local, production), but this package offers granular, low-level control (e.g., detecting PHP extensions, OS-specific paths, or HHVM-specific behaviors).if (Runtime::isLinux()) { ... }config(['app.php_version' => Environment::getPhpVersion()])).Trade-offs:
app()->make(Runtime::class)).Next steps:
composer require --dev sebastian/environment).Environment::isPhp80())."*For Test/QA: *"This package helps us standardize environment checks across tests and CI, reducing flaky tests due to runtime mismatches. For example:
Runtime::isHhvm().Environment::isPhp81()) to catch incompatible code early.Runtime::hasExtension('intl')) before tests run.
It’s a drop-in replacement for manual checks, so adoption is seamless."*How can I help you explore Laravel packages today?