public static function getDocumentID($source) 
    {
        if ($source instanceof DOMDOCUMENT) {
            foreach(phpQuery::$documents as $id => $document) {
                if ($source->isSameNode($document->document)) {
                    return $id;
                }
            }
        } else if ($source instanceof DOMNODE) {
            foreach(phpQuery::$documents as $id => $document) {
                if ($source->ownerDocument->isSameNode($document->document)) {
                    return $id;
                }
            }
        } else if ($source instanceof phpQueryObject) {
            return $source->getDocumentID();
        } else if (is_string($source) && isset(phpQuery::$documents[$source])) {
            return $source;
        }
    }