Skip to content

Fix round-tripping objects with numeric property names#18

Merged
nicolas-grekas merged 1 commit into
mainfrom
numeric-property-names
Jun 8, 2026
Merged

Fix round-tripping objects with numeric property names#18
nicolas-grekas merged 1 commit into
mainfrom
numeric-property-names

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member

A property named like a number (e.g. $o->{'999'}) lives in the object's property table as a verbatim string, but a PHP array normalizes that key to the integer 999. deepclone_to_array() emitted it as a non-canonical string array key, which differed from the polyfill's (array)-cast output and broke as soon as the payload went through var_export()/require (the OPcache cache-file path) or JSON, where "999" re-normalizes to 999 — a key deepclone_from_array() then rejected.

Numeric names are now stored as the canonical integer key on output and accepted as integer keys on input. Non-canonical names such as "007" stay strings. New .phpt covers the round-trip across direct / var_export / JSON, plus shared-object identity and hard refs through a numeric prop.

Fixes the extension side of symfony/symfony#64548. Companion polyfill PR: symfony/polyfill (DeepClone).

A property named like a number (e.g. $o->{'999'}) lives in the object's
property table as a verbatim string, but a PHP array normalizes that key
to the integer 999. deepclone_to_array() emitted it as a non-canonical
string array key: it differed from the polyfill's (array)-cast output and
broke as soon as the payload passed through var_export()/require (the
OPcache cache-file path) or JSON, where "999" re-normalizes to 999 — a key
deepclone_from_array() then rejected.

Store numeric names as the canonical integer key on output and accept
integer keys on input. Non-canonical names such as "007" stay strings.
Only dynamic properties can be numeric, so the declared-only fast path
skips the normalization probe entirely.

Fixes the extension side of symfony/symfony#64548.
@nicolas-grekas nicolas-grekas force-pushed the numeric-property-names branch from c97d6fb to 8f76541 Compare June 8, 2026 14:37
@nicolas-grekas nicolas-grekas reopened this Jun 8, 2026
@nicolas-grekas nicolas-grekas merged commit 8f76541 into main Jun 8, 2026
40 checks passed
@nicolas-grekas nicolas-grekas deleted the numeric-property-names branch June 8, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant