diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index cc868ff..0edcc89 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -88,6 +88,12 @@ impl serde::Serialize for PhpMixed { seq.end() } PhpMixed::Array(entries) => { + // PHP arrays do not distinguish an empty map from an empty list, and + // `json_encode([])` always emits `[]`. Mirror that so an empty associative + // array encodes as `[]` rather than `{}`. + if entries.is_empty() { + return serializer.serialize_seq(Some(0))?.end(); + } let mut map = serializer.serialize_map(Some(entries.len()))?; for (k, v) in entries { map.serialize_entry(k, v)?; |
