Skip to content

Deepclone final internal classes that lack a serialization API#5

Merged
nicolas-grekas merged 1 commit intosymfony:mainfrom
GromNaN:rule-a-probe-instantiability
Apr 10, 2026
Merged

Deepclone final internal classes that lack a serialization API#5
nicolas-grekas merged 1 commit intosymfony:mainfrom
GromNaN:rule-a-probe-instantiability

Conversation

@GromNaN
Copy link
Copy Markdown
Member

@GromNaN GromNaN commented Apr 10, 2026

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 bundled tidy extension) covers the probe path, and CI now loads tidy alongside mongodb.

This is the C extension counterpart of the polyfill fix in symfony/polyfill#562.

@GromNaN GromNaN force-pushed the rule-a-probe-instantiability branch from eda3d1b to 22967f8 Compare April 10, 2026 12:24
…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.
@GromNaN GromNaN force-pushed the rule-a-probe-instantiability branch from 22967f8 to 28dbe8b Compare April 10, 2026 12:25
@GromNaN GromNaN changed the title Rule A: probe instantiability for final internal classes without serialization API Deepclone final internal classes that lack a serialization API Apr 10, 2026
@nicolas-grekas nicolas-grekas merged commit 28dbe8b into symfony:main Apr 10, 2026
19 checks passed
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.

2 participants