nextcloud / nextcloud/openapi-extractor
Potential risky return of `array<string, …>`
Open
@provokateurin is already working on this.
Since May 19, 2025.
enhancement
- Dominant language
- PHP
- Stars
- 11
- Forks
- 4
- Avg merge
- 10h 18m
- Merged PRs (30d)
- 8
Description
If APIs return array<string, …> it is very likely that they are misbehaving on JSON.
Ref https://github.com/nextcloud/spreed/pull/10832
problem is that arrays are used for dictionaries and lists
Sample
<?php
$a = ['a' => true];
$b = [true];
var_dump($a, $b);
var_dump(json_encode($a), json_encode($b));
unset($a['a']);
unset($b[0]);
var_dump($a, $b);
var_dump(json_encode($a), json_encode($b));
Result
array(1) {
["a"]=>
bool(true)
}
array(1) {
[0]=>
bool(true)
}
string(10) "{"a":true}"
string(6) "[true]"
array(0) {
}
array(0) {
}
string(2) "[]" // 💔 JSON consumers would expect `"{}"` here
string(2) "[]"
Idea
We can help developers and signal: if you return array<string, …> you are mostlikely running into this error when your array is empty. The fixed return should be array<string, …>|\stdClass like in the Talk PR.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.