Deepclone final internal classes that lack a serialization API#5
Merged
nicolas-grekas merged 1 commit intosymfony:mainfrom Apr 10, 2026
Merged
Conversation
eda3d1b to
22967f8
Compare
…ation API Some final internal classes (e.g. tidyNode, MongoDB\BSON\MinKey/MaxKey) carry a C-level create_object handler but no __serialize/__unserialize/__sleep/__wakeup. Previously they were all rejected as not instantiable. Instead of rejecting them unconditionally, call object_init_ex() as a probe at class-info cache time. If the call succeeds the class is deepcloned normally; if it throws the class is still rejected. The probe runs once per class and its result is cached.
22967f8 to
28dbe8b
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.
Some final internal PHP classes (e.g.
tidyNode,MongoDB\BSON\MinKey,MongoDB\BSON\MaxKey) are perfectly constructible but have no__serialize/__unserialize/__sleep/__wakeup. The extension was rejecting all of them as not instantiable.This PR probes each such class once (at class-info cache time) by calling the C-level constructor. If it succeeds, the class is deepcloned normally; if it throws, the class is still rejected. The result is cached so the probe only runs once per class per request.
A PHPT test using
tidyNode(part of PHP's bundledtidyextension) covers the probe path, and CI now loadstidyalongsidemongodb.This is the C extension counterpart of the polyfill fix in symfony/polyfill#562.