-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/dom: Return numeric results from XPath callbacks as numbers #22105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --TEST-- | ||
| Returning scalar values from Dom\XPath callback | ||
| --EXTENSIONS-- | ||
| dom | ||
| --FILE-- | ||
| <?php | ||
| $dom = Dom\XMLDocument::createFromString('<root/>'); | ||
| $xpath = new Dom\XPath($dom); | ||
| $xpath->registerPhpFunctionNs('urn:x', 'get-int', fn(): int => 42); | ||
| $xpath->registerPhpFunctionNs('urn:x', 'get-float', fn(): float => 4.2); | ||
| $xpath->registerPhpFunctionNs('urn:x', 'get-string', fn(): string => "test"); | ||
| $xpath->registerPhpFunctionNs('urn:x', 'get-bool', fn(bool $b): bool => $b); | ||
| $xpath->registerNamespace('x', 'urn:x'); | ||
| var_dump($xpath->evaluate('x:get-int()')); | ||
| var_dump($xpath->evaluate('x:get-float()')); | ||
| var_dump($xpath->evaluate('x:get-string()')); | ||
| var_dump($xpath->evaluate('x:get-bool(1)')); | ||
| var_dump($xpath->evaluate('x:get-bool(0)')); | ||
| ?> | ||
| --EXPECT-- | ||
| float(42) | ||
| float(4.2) | ||
| string(4) "test" | ||
| bool(true) | ||
| bool(false) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -438,6 +438,10 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat | |
| valuePush(ctxt, xmlXPathNewNodeSet(nodep)); | ||
| } 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a BC break thus need a good UPGRADING entry.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will break for numbers >
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is what tests are for ;) |
||
| } else if (Z_TYPE(callback_retval) == IS_DOUBLE) { | ||
| valuePush(ctxt, xmlXPathNewFloat(Z_DVAL(callback_retval))); | ||
| } else if (Z_TYPE(callback_retval) == IS_OBJECT) { | ||
| zend_type_error("Only objects that are instances of DOM nodes can be converted to an XPath expression"); | ||
| zval_ptr_dtor(&callback_retval); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.