fix(UserConfig): cast getTypedValue() result to string in getValueBool() to fix PHP 8.4 TypeError#59630
Conversation
PHP 8.4 made passing non-strings to strtolower() a fatal TypeError. getTypedValue() can return a non-string when stored value type metadata doesn't align with ValueType::BOOL (e.g. user_ldap isDeleted preference). The (string) cast ensures strtolower() always receives a valid string. Fixes nextcloud#59629
But From your bug report: I am confused, "string given", then sounds like it is the correct type. Am I missing something? I don't get why |
|
Good catch on the confusing error message — you're right to question it. The file has The We've verified this fix in production on NC 33.0.2 / PHP 8.4. |
Summary
Fixes #59629
PHP 8.4 made passing non-strings to
strtolower()a fatalTypeError(previously a deprecation).UserConfig::getValueBool()callsstrtolower()directly on the return value ofgetTypedValue(), which can return a non-string when stored value type metadata doesn't align withValueType::BOOL.In practice this manifests when
user_ldapcallsgetValueBool($uid, 'user_ldap', 'isDeleted')— the storedisDeletedpreference has no type metadata, causinggetTypedValue()to return a non-string, which then breaksstrtolower()in PHP 8.4.Change
One-character fix: add
(string)cast before thestrtolower()call. This is safe and defensive —getTypedValue()is already declared to returnstring, so this is a no-op in the happy path and a guard for edge cases.Impact
Without this fix, on PHP 8.4 + NC 33 with
user_ldapenabled:TypeError: strtolower(): Argument #1 ($string) must be of type string, string givenRelated
user_ldapfix