Skip to content

Commit 28fbf8c

Browse files
committed
fix(config): add null coalescing fallback in getValueBool before strtolower
Followup to #59646: guard against null reaching strtolower() in both AppConfig and UserConfig getValueBool(). Also aligns AppConfig with the (string) cast added in UserConfig by the original PR. Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent cbc8033 commit 28fbf8c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/private/AppConfig.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ public function getValueFloat(string $app, string $key, float $default = 0, bool
437437
*/
438438
#[\Override]
439439
public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool {
440-
$b = strtolower($this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL));
440+
// The explicit (string) cast guards against a PHP OPcache bug where values passed
441+
// by reference across function boundaries can have their type corrupted (e.g. bool
442+
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
443+
// https://github.com/php/php-src/pull/21973. Keep until minimum PHP version is bumped.
444+
$b = strtolower((string)$this->getTypedValue($app, $key, $default ? 'true' : 'false', $lazy, self::VALUE_BOOL) ?? 'false');
441445
return in_array($b, ['1', 'true', 'yes', 'on']);
442446
}
443447

lib/private/Config/UserConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public function getValueBool(
709709
// by reference across function boundaries can have their type corrupted (e.g. bool
710710
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
711711
// https://github.com/php/php-src/pull/21973. Keep until minimum PHP version is bumped.
712-
$b = strtolower((string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
712+
$b = strtolower((string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL) ?? 'false');
713713
return in_array($b, ['1', 'true', 'yes', 'on']);
714714
}
715715

0 commit comments

Comments
 (0)