[DeepClone] Suggest the extension when refusing a named callable, and decode its global-function references#635
Merged
Conversation
… decode its global-function references Two related improvements to how the polyfill cooperates with the extension on first-class callables declared in constant expressions. Refusal message. deepclone_to_array() refuses to serialize a closure over a named callable unless allow_named_closures is set. The message now warns that the option should only be enabled for trusted input, and points at the extension: for a first-class callable declared in a constant expression (including cross-class references such as Validators::check(...) and global functions such as strlen(...)) the extension recovers the declaring class from reflection and serializes the closure as a declaration-site reference, needing no opt-in. Userland has no equivalent reflection hook. This path only runs when the extension is absent, so the suggestion always applies. Decoding the extension's global-function references. The extension can encode a reference to a global internal function declared in an attribute; such a function has no start line, so the reference is stored with line 0. The polyfill cannot produce these, but must decode them: ReflectionFunction reports no start line for an internal function, so a line-0 reference is normalized rather than treated as stale.
f3fb2b7 to
bcc4f2b
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.
Two related improvements to how the polyfill cooperates with the extension on first-class callables declared in constant expressions.
Refusal message.
deepclone_to_array()refuses to serialize a closure over a named callable unlessallow_named_closuresis set. The message now warns that the option should only be enabled for trusted input, and points at the extension, which resolves more of these without the opt-in — a first-class callable declared in a constant expression, including cross-class references (Validators::check(...)) and global functions (strlen(...)), gets its declaring class recovered from reflection and is serialized as a declaration-site reference. Userland has no equivalent reflection hook, and this path only runs when the extension is absent, so the suggestion always applies.Decoding the extension's global-function references. The extension can encode a reference to a global internal function declared in an attribute; such a function has no start line, so the reference is stored with line
0. The polyfill cannot produce these (no reflection hook), but must be able to decode them.ReflectionFunction::getStartLine()returnsfalsefor an internal function, so aline 0reference was wrongly treated as stale; it is now normalized. With this, an extension-produced reference to a global internal function in an attribute round-trips through the polyfill.The leading part of the refusal message is unchanged, so the tests (which match a substring) and any callers matching on it are unaffected.
Companion extension implementation: symfony/php-ext-deepclone#27