Open
Description
If APIs return array<string, …>
it is very likely that they are misbehaving on JSON.
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.