From 7c847bf896e80d028c48973b15b681203a1509c1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 18:55:18 +0900 Subject: fix(php-shim): encode empty PhpMixed::Array as [] PHP arrays do not distinguish an empty map from an empty list, and json_encode([]) always emits []. The Serialize impl emitted {} for an empty associative array, which diverged from Composer when computing the lock file content-hash for a composer.json with an empty require. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/shirabe-php-shim/src/lib.rs') 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)?; -- cgit v1.3.1