[DeepClone] Drop SPL "\0" special key from deepclone_hydrate()#584
Merged
nicolas-grekas merged 1 commit into1.xsymfony/polyfill:1.xfrom Apr 26, 2026
Merged
[DeepClone] Drop SPL "\0" special key from deepclone_hydrate()#584nicolas-grekas merged 1 commit into1.xsymfony/polyfill:1.xfrom
nicolas-grekas merged 1 commit into1.xsymfony/polyfill:1.xfrom
Conversation
Mirrors the C extension change (symfony/php-ext-deepclone#17). ArrayObject, ArrayIterator and SplObjectStorage all ship __serialize / __unserialize since PHP 7.4 — callers populate them the standard way: $ao = deepclone_hydrate('ArrayObject'); $ao->__unserialize([ArrayObject::ARRAY_AS_PROPS, ['x' => 1], []]); The mangled-key resolution path is unchanged; only the SPL fast-path is removed. Symfony's Hydrator/Instantiator retain BC by translating the legacy "\0" shape to __unserialize() themselves.
50868fc to
a805169
Compare
nicolas-grekas
added a commit
to symfony/symfony
that referenced
this pull request
Apr 26, 2026
…lize() in Hydrator/Instantiator (nicolas-grekas) This PR was merged into the 8.1 branch. Discussion ---------- [VarExporter] Translate legacy SPL "\0" key to __unserialize() in Hydrator/Instantiator | Q | A | ------------- | --- | Branch? | 8.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT `deepclone_hydrate()` no longer treats the special `"\0"` key as SPL internal state (see symfony/php-ext-deepclone#17 / symfony/polyfill#584). `ArrayObject`, `ArrayIterator` and `SplObjectStorage` all ship `__serialize` / `__unserialize` since PHP 7.4 — the C extension and polyfill now expect callers to use the standard path. This PR keeps BC for `Hydrator::hydrate()` and `Instantiator::instantiate()`: when `$mangledVars` contains a `"\0"` key with the legacy shape, it is intercepted and translated to a `__unserialize()` call. Mapping: * `SplObjectStorage`: `"\0" => [$obj1, $info1, $obj2, $info2, ...]` → `__unserialize([[$obj1, $info1, ...], []])` * `ArrayObject`: `"\0" => [$array, $flags?, $iteratorClass?]` → `__unserialize([$flags ?? 0, $array, [], $iteratorClass ?? ArrayIterator::class])` * `ArrayIterator`: `"\0" => [$array, $flags?]` → `__unserialize([$flags ?? 0, $array, []])` In `Instantiator::instantiate()`, the `__unserialize()` call happens after instantiation so the constructor is still skipped. Depends on symfony/polyfill#584 (which depends on symfony/php-ext-deepclone#17). Commits ------- 54d013b [VarExporter] Translate legacy SPL "\0" key to __unserialize() in Hydrator/Instantiator
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.
Mirrors symfony/php-ext-deepclone#17.
ArrayObject, ArrayIterator and SplObjectStorage all ship
__serialize/__unserializesince PHP 7.4. The"\0"special key indeepclone_hydrate()was a port from Symfony's legacy Hydrator API and added bespoke handling that duplicated what these classes natively expose.Callers now populate these objects the standard way:
Or just round-trip via
deepclone_from_array(), which routes through__unserializenatively.The mangled-key resolution path (
"propName","\0*\0prop","\0Class\0prop") is unchanged; only the SPL fast-path is removed. Tests updated to use__unserialize().Symfony's
Hydrator::hydrate()/Instantiator::instantiate()keep BC by translating the legacy"\0"shape to__unserialize()themselves.