File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ --TEST--
2+ Returning scalar values from Dom\XPath callback
3+ --EXTENSIONS--
4+ dom
5+ --FILE--
6+ <?php
7+ $ dom = Dom \XMLDocument::createFromString ('<root/> ' );
8+ $ xpath = new Dom \XPath ($ dom );
9+ $ xpath ->registerPhpFunctionNs ('urn:x ' , 'get-number ' , fn () => 42 );
10+ $ xpath ->registerPhpFunctionNs ('urn:x ' , 'get-string ' , fn () => "test " );
11+ $ xpath ->registerPhpFunctionNs ('urn:x ' , 'get-bool ' , fn (bool $ b ) => $ b );
12+ $ xpath ->registerNamespace ('x ' , 'urn:x ' );
13+ var_dump ($ xpath ->evaluate ('x:get-number() ' ));
14+ var_dump ($ xpath ->evaluate ('x:get-string() ' ));
15+ var_dump ($ xpath ->evaluate ('x:get-bool(1) ' ));
16+ var_dump ($ xpath ->evaluate ('x:get-bool(0) ' ));
17+ ?>
18+ --EXPECT--
19+ float(42)
20+ string(4) "test"
21+ bool(true)
22+ 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
438438 valuePush (ctxt , xmlXPathNewNodeSet (nodep ));
439439 } else if (Z_TYPE (callback_retval ) == IS_FALSE || Z_TYPE (callback_retval ) == IS_TRUE ) {
440440 valuePush (ctxt , xmlXPathNewBoolean (Z_TYPE (callback_retval ) == IS_TRUE ));
441+ } else if (Z_TYPE (callback_retval ) == IS_LONG ) {
442+ valuePush (ctxt , xmlXPathNewFloat (Z_LVAL (callback_retval )));
443+ } else if (Z_TYPE (callback_retval ) == IS_DOUBLE ) {
444+ valuePush (ctxt , xmlXPathNewFloat (Z_DVAL (callback_retval )));
441445 } else if (Z_TYPE (callback_retval ) == IS_OBJECT ) {
442446 zend_type_error ("Only objects that are instances of DOM nodes can be converted to an XPath expression" );
443447 zval_ptr_dtor (& callback_retval );
You can’t perform that action at this time.
0 commit comments