ext/dom: Return numeric results from XPath callbacks as numbers #22105
Draft
afflerbach wants to merge 1 commit into
Draft
ext/dom: Return numeric results from XPath callbacks as numbers #22105afflerbach wants to merge 1 commit into
afflerbach wants to merge 1 commit into
Conversation
8388fe6 to
dc37660
Compare
Member
|
nice additions, want to see a bit more in the tests area, I ll write few remarks shortly. |
devnexen
reviewed
May 21, 2026
| <?php | ||
| $dom = Dom\XMLDocument::createFromString('<root/>'); | ||
| $xpath = new Dom\XPath($dom); | ||
| $xpath->registerPhpFunctionNs('urn:x', 'get-int', fn(): int => 42); |
Member
There was a problem hiding this comment.
- you should also test edge cases such as NAN, PHP_INT_MIN/MAX ...
- Using XSLTProcessor::registerPHPFunctions for returning an int/float to assert proper values even as strings.
- demonstrating benefits of your changes through an expression, e.g. x:get-int() + 1
| } else if (Z_TYPE(callback_retval) == IS_FALSE || Z_TYPE(callback_retval) == IS_TRUE) { | ||
| valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(callback_retval) == IS_TRUE)); | ||
| } else if (Z_TYPE(callback_retval) == IS_LONG) { | ||
| valuePush(ctxt, xmlXPathNewFloat(Z_LVAL(callback_retval))); |
Member
There was a problem hiding this comment.
this is a BC break thus need a good UPGRADING entry.
Member
There was a problem hiding this comment.
I think this will break for numbers > 2**52 on 64-bit systems. Previously, it was represented as a string and could be coerced back to a php int without precision loss. Doubles can't reliably store integers > 2**52 so you would get precision loss.
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.
not as string
see https://www.w3.org/TR/xpath-10/#numbers