Fix round-tripping objects with numeric property names#18
Merged
Conversation
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.
c97d6fb to
8f76541
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 integer999.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 throughvar_export()/require(the OPcache cache-file path) or JSON, where"999"re-normalizes to999— a keydeepclone_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.phptcovers 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).