OK, so maybe PHP's getElementById() is behaving according to spec, but it does not have the behaviour that people *want*...
Below is a global getElementById() function (i.e. not a DOMDocument method) which recursively searches through a document for a certain id value.
/* Find the first element in the document (sub)tree whose id attribute
   has the value $id. By default, the entire document is searched - pass
   a non-NULL value in $node to search only the subtree below $node. */
function getElementById(DOMDocument $doc, /*string*/ $id,
                        DOMNode $node = NULL) {
  if ($node === NULL) return getElementById($doc, $id, $doc->documentElement);
  $children = $node->childNodes;
  for ($i = 0; $i < $children->length; ++$i) {
    $elem = $children->item($i);
    if (!($elem instanceof DOMElement)) continue;
    if ($elem->getAttribute('id') == $id) return $elem;
    $ret = getElementById($doc, $id, $elem);
    if ($ret !== NULL) return $ret;
  }
  return NULL;
}