Troubleshooting

Config package issues and fixes.

Loading Issues

Config file not found

Problem: FileNotFoundException: Config file not found

Cause: Wrong path or file doesn't exist.

Fix: Verify path:

$path = $context->path('config');
if (!is_dir($path)) {
    // config directory doesn't exist
}

$config->load($path);

Config not loading in production

Problem: Config values empty in production.

Cause: Path issues on production server.

Fix: Use realpath() and verify:

$configPath = realpath($context->path('config'));
if ($configPath === false) {
    throw new \RuntimeException('Config path does not exist');
}
$config->load($configPath);

Access Issues

Dot notation returns null

Problem: $config->get('app.database.host') returns null.

Cause: Array structure doesn't match dot path.

Fix: Verify structure matches:

// config/app.php
return [
    'database' => [        // 'app.database'
        'host' => 'localhost',  // 'app.database.host'
    ],
];

// Access
$config->get('app.database.host'); // 'localhost'

Returns entire array instead of value

Problem: get('database') returns array, expected string.

Cause: Requested parent key, not leaf value.

Fix: Access specific key or handle array:

// Get specific value
$host = $config->get('database.host');

// Or handle array
$db = $config->get('database');
$host = $db['host'] ?? 'localhost';

Environment Issues

Environment override not working

Problem: local config doesn't override production.

Cause: WP_ENVIRONMENT_TYPE not set or wrong.

Fix: Check environment detection:

// wp-config.php
define('WP_ENVIRONMENT_TYPE', 'local');

// Verify
echo wp_get_environment_type(); // Should be 'local'

Wrong environment in staging

Problem: Staging uses production config.

Cause: Missing environment-specific file.

Fix: Create environment override:

config/
+-- app.php           # Base config
+-- app.staging.php   # Staging override
+-- app.production.php