Skip to content

Commit bca11ce

Browse files
Merge pull request #59646 from thereisnotime/fix/userconfig-getvaluebool-strtolower-type-error-v2
fix(UserConfig): cast getTypedValue() result to string in getValueBool()
2 parents 8fe81f6 + ab08261 commit bca11ce

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
@@ -3566,6 +3566,11 @@
35663566
<code><![CDATA[$CONFIG]]></code>
35673567
</UndefinedVariable>
35683568
</file>
3569+
<file src="lib/private/Config/UserConfig.php">
3570+
<RedundantCast>
3571+
<code><![CDATA[(string)$this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL)]]></code>
3572+
</RedundantCast>
3573+
</file>
35693574
<file src="lib/private/Console/Application.php">
35703575
<NoInterfaceProperties>
35713576
<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
@@ -705,7 +705,11 @@ public function getValueBool(
705705
bool $default = false,
706706
bool $lazy = false,
707707
): bool {
708-
$b = strtolower($this->getTypedValue($userId, $app, $key, $default ? 'true' : 'false', $lazy, ValueType::BOOL));
708+
// The explicit (string) cast guards against a PHP OPcache bug where values passed
709+
// by reference across function boundaries can have their type corrupted (e.g. bool
710+
// returned as int). Affects PHP 8.x with OPcache enabled; fixed upstream in
711+
// 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));
709713
return in_array($b, ['1', 'true', 'yes', 'on']);
710714
}
711715

0 commit comments

Comments
 (0)