From 523f4c5f5ae3b42516449512e15b7f298a7fef1e Mon Sep 17 00:00:00 2001 From: Mohamed Abd-Elfattah <41032112+7amoood@users.noreply.github.com> Date: Sat, 4 Oct 2025 16:46:47 +0300 Subject: [PATCH] Use getenv() instead of $_ENV in bootstrap file to ensure environment variables are accessible This PR updates the `bootstrap` file to use `getenv()` instead of `$_ENV` when retrieving environment variables. In some PHP configurations, `$_ENV` returns `null` unless the `variables_order` setting in `php.ini` includes the `E` flag. This can cause Octane to fail when resolving the application base path or vendor directory. By switching to `getenv()`, Octane can reliably fetch environment variables without requiring users to modify their PHP configuration. ### Changes - Replaced `$_ENV['APP_RUNNING_IN_CONSOLE']` with `getenv('APP_RUNNING_IN_CONSOLE')`. - Ensured `COMPOSER_VENDOR_DIR` and other variables are resolved consistently. ### Why When extending the Swoole server start process and attempting to change the vendor file path, `$_ENV` returned `null` unless `variables_order` was explicitly configured. This fix ensures smoother setup for developers across different environments. ### Impact - No breaking changes. - Improves reliability of environment variable handling in Swoole/Octane bootstrap. --- bin/bootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/bootstrap.php b/bin/bootstrap.php index cbd66138d..58ddef357 100644 --- a/bin/bootstrap.php +++ b/bin/bootstrap.php @@ -15,7 +15,7 @@ | */ -$basePath = $_SERVER['APP_BASE_PATH'] ?? $_ENV['APP_BASE_PATH'] ?? $serverState['octaneConfig']['base_path'] ?? null; +$basePath = $_SERVER['APP_BASE_PATH'] ?? getenv('APP_BASE_PATH') ?? $serverState['octaneConfig']['base_path'] ?? null; if (! is_string($basePath)) { echo 'Cannot find application base path.'; @@ -35,7 +35,7 @@ | */ -$vendorDir = $_ENV['COMPOSER_VENDOR_DIR'] ?? "{$basePath}/vendor"; +$vendorDir = getenv('COMPOSER_VENDOR_DIR') ?? "{$basePath}/vendor"; if (! is_file($autoload_file = "{$vendorDir}/autoload.php")) { echo "Composer autoload file was not found. Did you install the project's dependencies?";