diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 18:55:18 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 18:55:18 +0900 |
| commit | 7c847bf896e80d028c48973b15b681203a1509c1 (patch) | |
| tree | 468189bce5c269828306f739fc00985dedd74fbb /crates/shirabe-php-shim/src | |
| parent | 0d6cd1b3b5783c03dd8520ac65e9156d476a7a64 (diff) | |
| download | php-shirabe-7c847bf896e80d028c48973b15b681203a1509c1.tar.gz php-shirabe-7c847bf896e80d028c48973b15b681203a1509c1.tar.zst php-shirabe-7c847bf896e80d028c48973b15b681203a1509c1.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src')
| -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)?; |
