|
| 1 | +--TEST-- |
| 2 | +DOMXPath: Reentrant evaluation must restore the context node and namespaces |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +$doc = new DOMDocument(); |
| 8 | +$doc->loadXML('<r xmlns:p="urn:p"><a><x>A</x><p:y/></a><a><x>A2</x></a><b><x>B</x><x>B2</x><x>B3</x></b></r>'); |
| 9 | +$xp = new DOMXPath($doc); |
| 10 | +$xp->registerNamespace('php', 'http://php.net/xpath'); |
| 11 | +$xp->registerPhpFunctions(); |
| 12 | +$b = $doc->documentElement->lastElementChild; |
| 13 | +$GLOBALS['xp'] = $xp; |
| 14 | +$GLOBALS['b'] = $b; |
| 15 | +function callback($node) { |
| 16 | + $GLOBALS['xp']->query('x[2]', $GLOBALS['b']); |
| 17 | + return true; |
| 18 | +} |
| 19 | + |
| 20 | +echo "context node:\n"; |
| 21 | +var_dump($xp->query('a[php:function("callback", .) and x]', $doc->documentElement)->length); |
| 22 | +var_dump($xp->evaluate('count(a[php:function("callback", .) and x])', $doc->documentElement)); |
| 23 | + |
| 24 | +echo "in-scope namespace:\n"; |
| 25 | +var_dump($xp->query('a[php:function("callback", .) and p:y]', $doc->documentElement)->length); |
| 26 | + |
| 27 | +echo "position and size:\n"; |
| 28 | +var_dump($xp->query('a[php:function("callback", .) and position() = 2]', $doc->documentElement)->length); |
| 29 | +var_dump($xp->query('a[php:function("callback", .) and last() = 2]', $doc->documentElement)->length); |
| 30 | + |
| 31 | +echo "after reentry:\n"; |
| 32 | +var_dump($xp->query('a[x]', $doc->documentElement)->length); |
| 33 | + |
| 34 | +echo "Dom\\XPath:\n"; |
| 35 | +$modern = Dom\XMLDocument::createFromString('<r><a><x>A</x></a><a><x>A2</x></a><b><x>B</x><x>B2</x><x>B3</x></b></r>'); |
| 36 | +$GLOBALS['xp'] = new Dom\XPath($modern); |
| 37 | +$GLOBALS['xp']->registerNamespace('php', 'http://php.net/xpath'); |
| 38 | +$GLOBALS['xp']->registerPhpFunctions(); |
| 39 | +$GLOBALS['b'] = $modern->documentElement->lastElementChild; |
| 40 | +var_dump($GLOBALS['xp']->query('a[php:function("callback", .) and x]', $modern->documentElement)->length); |
| 41 | +?> |
| 42 | +--EXPECT-- |
| 43 | +context node: |
| 44 | +int(2) |
| 45 | +float(2) |
| 46 | +in-scope namespace: |
| 47 | +int(1) |
| 48 | +position and size: |
| 49 | +int(1) |
| 50 | +int(2) |
| 51 | +after reentry: |
| 52 | +int(2) |
| 53 | +Dom\XPath: |
| 54 | +int(2) |
0 commit comments