[DeepClone] Add deepclone_hydrate() polyfill#568
Merged
nicolas-grekas merged 1 commit into1.xfrom Apr 12, 2026
Merged
Conversation
912efb8 to
7d23c4f
Compare
7d23c4f to
626b477
Compare
nicolas-grekas
added a commit
to symfony/symfony
that referenced
this pull request
Apr 12, 2026
…nd Instantiator (nicolas-grekas) This PR was merged into the 8.1 branch. Discussion ---------- [VarExporter] Leverage deepclone_hydrate() in Hydrator and Instantiator | Q | A | ------------- | --- | Branch? | 8.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT `Hydrator::hydrate()` and `Instantiator::instantiate()` now delegate directly to `deepclone_hydrate()` from `symfony/polyfill-deepclone` (or the native `ext-deepclone`). This removes ~350 lines of internal hydration/instantiation machinery: - `Internal\Hydrator` class deleted — `$propertyScopes` / `getPropertyScopes()` and the two constants moved to `LazyObjectRegistry` where they belong (used by the lazy proxy infrastructure) - `Internal\Values` class deleted (unused) - `Hydrator::hydrate()` is now a one-liner delegate - `Instantiator::instantiate()` is now a thin try/catch wrapper for exception mapping The `deepclone_hydrate()` function handles: - Scoped property writes via `EG(fake_scope)` + direct OBJ_PROP slot access (readonly, typed, references) - Mangled property resolution from `(array)` format - SPL special cases (ArrayObject, ArrayIterator, SplObjectStorage) - Instantiability validation (same rules as `deepclone_from_array()`) Depends on symfony/polyfill#568 and symfony/php-ext-deepclone#6. Commits ------- de52ade [VarExporter] Leverage deepclone_hydrate() in Hydrator and 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.
Pure-PHP implementation of
deepclone_hydrate(object|string $object_or_class, array $scoped_vars = [], array $mangled_vars = []): object, matching the C extension (symfony/php-ext-deepclone#6).$scoped_varswrites directly withClosure::bindfor scope access$mangled_varsresolves mangled keys ("\0Class\0prop","\0*\0prop") to the correct scope"\0"key: ArrayObject/ArrayIterator constructor, SplObjectStorage attach&reference preservation via$object->$name = $value; $object->$name = &$value;getClassReflector()(same rules asdeepclone_from_array)ValueErroron integer keys in$mangled_varsor non-array values in$scoped_varsgetClassReflector()now rejects enums$allowed_classes,$object_or_class, etc.)