Hi internals,

Currently we do not allow (*) creating empty property names on objects, i.e.

    $obj->{''} = 42;

is illegal. While empty property names are unlikely to be useful per se,
they are problematic for deserialization of foreign formats like JSON. To
avoid this issue {"": null} will currently decode to a property named
"_empty_" rather than "". Notably, this means that JSON decode and encode
do not round-trip (as we do not convert _empty_ back to an empty name while
encoding).

There is no technical reason (that I can see) for keeping this arbitrary
restriction. I believe that the original reason for the restriction was our
use of NUL-prefixed property names for name mangling, combined with the
fact that an empty string at the C level happens to "start" with a NUL byte.

A patch to drop the restriction and allow empty property names:
https://github.com/php/php-src/pull/1836 It does not touch the JSON
handling, as there are BC concerns involved there, I leave that to the
ext/json maintainer.

Any objections to changing this?

Regards,
Nikita

(*) There are roundabout ways to create them anyway.

Reply via email to