Search code examples
phpobjectsyntaxfeedparserphp4

Parse error while chaining object methods in PHP4


I have a client who needs a website urgently, but I have no access to information such as the control panel.

PHP Version is 4.4 Which is a pain as I'm used to 5.

The first problem is I keep getting:

Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37

This is the function in question:

function read_rss($display=0,$url='') {
    $doc = new DOMDocument();
    $doc->load($url);
    $itemArr = array();

    foreach ($doc->getElementsByTagName('item') as $node) {
        if ($display == 0) {
            break;
        }

        $itemRSS = array(
            'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
            'description'=>$node->getElementsByTagName('description')->item(0)->nodeValue,
            'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue);

         array_push($itemArr, $itemRSS);

        $display--;
    }
    return $itemArr;
}

And the line in question:

'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,

Solution

  • PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...