1--TEST-- 2compareDocumentPosition: contains nodes as a descendent in a longer path 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$dom = new DOMDocument(); 9$dom->loadXML(<<<XML 10<?xml version="1.0"?> 11<container> 12 <a> 13 <b/> 14 <c> 15 <d/> 16 </c> 17 </a> 18</container> 19XML); 20 21$xpath = new DOMXPath($dom); 22$container = $xpath->query("//container")->item(0); 23 24foreach (["a", "b", "c", "d"] as $tag) { 25 echo "--- Test $tag ---\n"; 26 $element = $xpath->query("//$tag")->item(0); 27 var_dump($container->compareDocumentPosition($element) === (DOMNode::DOCUMENT_POSITION_FOLLOWING | DOMNode::DOCUMENT_POSITION_CONTAINED_BY)); 28 var_dump($element->compareDocumentPosition($container) === (DOMNode::DOCUMENT_POSITION_PRECEDING | DOMNode::DOCUMENT_POSITION_CONTAINS)); 29} 30 31?> 32--EXPECT-- 33--- Test a --- 34bool(true) 35bool(true) 36--- Test b --- 37bool(true) 38bool(true) 39--- Test c --- 40bool(true) 41bool(true) 42--- Test d --- 43bool(true) 44bool(true) 45