Skip to content

Commit 476da53

Browse files
thereisnotimebackportbot[bot]
authored andcommitted
fix(UserConfig): cast getTypedValue() result to string in getValueBool()
PHP 8.4 made passing non-strings to strtolower() a fatal TypeError. getTypedValue() can return a non-string under certain conditions, causing the strtolower() call to throw. The (string) cast guards against this. Signed-off-by: There Is No TIme <37583483+thereisnotime@users.noreply.github.com> Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent ae35968 commit 476da53

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

build/psalm-baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,6 +3485,11 @@
34853485
<code><![CDATA[$CONFIG]]></code>
34863486
</UndefinedVariable>
34873487
</file>
3488+
<file src="lib/private/Config/UserConfig.php">
3489+
<RedundantCast>
3490+
<code><![CDATA[(string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL)]]></code>
3491+
</RedundantCast>
3492+
</file>
34883493
<file src="lib/private/Console/Application.php">
34893494
<NoInterfaceProperties>
34903495
<code><![CDATA[$this->request->server]]></code>

lib/private/Config/UserConfig.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ public function getValueBool(
682682
bool $default = false,
683683
bool $lazy = false,
684684
): bool {
685-
$b = strtolower($this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
685+
// The explicit (string) cast guards against a PHP OPcache bug where values passed
686+
// by reference across function boundaries can have their type corrupted (e.g. bool
687+
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
688+
// https://github.com/php/php-src/pull/21973. Keep until minimum PHP version is bumped.
689+
$b = strtolower((string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
686690
return in_array($b, ['1', 'true', 'yes', 'on']);
687691
}
688692

0 commit comments

Comments
 (0)