Skip to content

[DeepClone] Add deepclone_hydrate() polyfill#568

Merged
nicolas-grekas merged 1 commit into1.xfrom
deepclone
Apr 12, 2026
Merged

[DeepClone] Add deepclone_hydrate() polyfill#568
nicolas-grekas merged 1 commit into1.xfrom
deepclone

Conversation

@nicolas-grekas
Copy link
Copy Markdown
Member

@nicolas-grekas nicolas-grekas commented Apr 11, 2026

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_vars writes directly with Closure::bind for scope access
  • $mangled_vars resolves mangled keys ("\0Class\0prop", "\0*\0prop") to the correct scope
  • SPL special "\0" key: ArrayObject/ArrayIterator constructor, SplObjectStorage attach
  • PHP & reference preservation via $object->$name = $value; $object->$name = &$value;
  • Instantiability validation reuses getClassReflector() (same rules as deepclone_from_array)
  • ValueError on integer keys in $mangled_vars or non-array values in $scoped_vars
  • Fix: getClassReflector() now rejects enums
  • All parameters renamed to snake_case ($allowed_classes, $object_or_class, etc.)

@nicolas-grekas nicolas-grekas merged commit f5384f9 into 1.x Apr 12, 2026
2 of 18 checks passed
@nicolas-grekas nicolas-grekas deleted the deepclone branch April 12, 2026 08:45
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
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