[php-src] Issue #21972: Corrupted variable type `Argument #1 ($string) must be of type string, string given`
| From: | susnux | Date: | Thu, 07 May 2026 08:09:07 +0000 |
| Subject: | [php-src] Issue #21972: Corrupted variable type `Argument #1 ($string) must be of type string, string given` | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252051@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/21972
Author: susnux
### Description
The following code:
```php
<?php
declare(strict_types=1);
// ...
class MyClass {
// ...
public function getValueBool(): bool {
$b = strtolower($this->getTypedValue(), ValueType::BOOL));
// ...
}
protected function getTypedValue(): string {
// ...
}
}
```
Resulted in this output:
```
TypeError: strtolower(): Argument #1 ($string) must be of type string, string given
```
But I expected this output instead:
```
$b = "false"
```
---
What is confusing here is that we use strict types thus the return type of
getTypedValue always has to be a string. This does not throw a TypeError so it should
be a string.
If we add more debugging to the return value before putting it to strtolower, we can
see:
value: "false"
type: "unknown type" (when using gettype($returnValue)
In our real code base its this line:
https://github.com/nextcloud/server/blob/57a2630be741ce039929830294b93982587e9ec3/lib/private/Config/UserConfig.php#L708
We [received a bug
ourself](https://github.com/nextcloud/server/issues/59629#issuecomment-4376099184) but I suspect
this is a php bug from the TypeError received and the "unknown type" type
### PHP Version
```plain
8.4.20
```
### Operating System
Ubuntu / docker