2 Sep 2026 · Grav CMS
When GRAV_CONFIG__…=false means true
Environment variables are always strings, and (bool)"false" is true in PHP. A small cast fixed a config override that did the opposite of what it said.
Grav lets you override any config key with an environment variable such as GRAV_CONFIG__system__cache__enabled=false. Issue #4277 reported that this setting left the cache on.
Root cause
Environment variables are always strings, so the config received the string "false". Core reads flags like this with a (bool) cast, and in PHP any non-empty string other than "0" is true. The override did the opposite of what it said, and nothing in the logs hinted at it.
The fix
The env override loop in initializeConfig() now passes each value through a small helper before it is stored:
protected static function castEnvironmentValue(mixed $value): mixed
{
if (is_string($value)) {
if (strcasecmp($value, 'true') === 0) {
return true;
}
if (strcasecmp($value, 'false') === 0) {
return false;
}
}
return $value;
}The key decision was what not to convert. "0", "1", numbers, "yes" and padded strings like " true " pass through unchanged, so existing setups behave exactly as before. Only the two unambiguous literals are converted.
The tests follow the reflection plus data provider pattern the file already used, with 16 cases that document both what is converted and what is deliberately left alone. It was merged into the develop branch.