What are some common pitfalls when using XPath with namespaces in PHP?

A common pitfall when using XPath with namespaces in PHP is not properly registering the namespaces before querying the XML document. To solve this issue, you need to register the namespaces using the `registerXPathNamespace` method of the `DOMXPath` class. This method allows you to map a prefix to a namespace URI, which can then be used in your XPath queries.

// Load the XML document
$xml = new DOMDocument();
$xml->load('file.xml');

// Create a new XPath object
$xpath = new DOMXPath($xml);

// Register the namespaces
$xpath->registerNamespace('ns', 'http://example.com/namespace');

// Perform an XPath query with the registered namespace
$nodes = $xpath->query('//ns:element');

// Iterate over the results
foreach ($nodes as $node) {
    echo $node->nodeValue . "\n";
}