Fixes #2869

Ported https://bugs.php.net/bug.php?id=66021.
We need it in `writeArrayFooter()` as well.