tontof / kriss_feed

A simple and smart (or stupid) feed reader
282 stars 54 forks source link

Fatal error: Uncaught Error: Call to undefined method DOMNodeList::getElementsByTagName() in index.php:4737 #410

Open jerrywham opened 5 years ago

jerrywham commented 5 years ago

If $node is not defined, getElementsByTagsName is undefined. I propose this fix


    public static function getNodesName($node, $name)
    {
        if (strpos($name, ':') !== false) {
            list(, $localname) = explode(':', $name);
            $nodes = $node->getElementsByTagNameNS('*', $localname);
        } else {
            if (isset($node->length)) {
                $nodes = $node->getElementsByTagName($name);
            } else {
                $nodes = new stdClass();
                $nodes->length = 0;
            }
        }

        return self::filterNodeListByName($nodes, $name);
    }
tontof commented 5 years ago

I guess $node should not be undefined. Can you provide a link to reproduce the problem ?

To be more generic I propose this fix:

public static function getNodesName($node, $name)
{
   if (!isset($node->length)) {
    return new DOMNodeList();
   }
   /* original function code */
}