Good Code
The good version reads a required secret from the runtime environment and fails during startup if it is missing.
Lesson 09
Load configuration from the environment and fail clearly when required secrets are missing.
<?php declare(strict_types=1);
$databaseUrl = getenv('DATABASE_URL');
if ($databaseUrl === false || $databaseUrl === '') {
throw new RuntimeException('DATABASE_URL is required.');
}
return [
'url' => $databaseUrl,
'timeout_seconds' => 3,
];<?php
return [
'url' => 'mysql://root:secret-password@localhost/app',
'timeout_seconds' => $_GET['timeout'] ?? 30,
];The good version reads a required secret from the runtime environment and fails during startup if it is missing.
The bad version commits credentials and allows a request value to influence infrastructure configuration.