0

I'm having a bit of trouble defining a property in a PHP class I'm creating.

<?php
class news_parser {
    public $var1 = Array();
    function contents($parser, $data) {
        printf($data);
    }
    function start_tag($parser, $data, $attribs) {
        printf($data);
    }
    function end_tag($parser, $data) {
        printf($data);
    }
    function parse() {
        if(!$file = fopen("http://services.digg.com/2.0/story.getTopNews?type=rss&topic=technology", "r"))
            die("Error opening file");
        $data = fread($file, 80000);

        $xml_parser = xml_parser_create();
        xml_set_element_handler($xml_parser, array($this, "start_tag"), array($this, "end_tag"));
        xml_set_character_data_handler($xml_parser, array($this, "contents"));
        if(!xml_parse($xml_parser, $data, feof($fh)))
            die("Error on line " . xml_get_current_line_number($xml_parser));
        xml_parser_free($xml_parser);
        fclose($fh);
    }
}

$digg_parser = new news_parser();
$digg_parser->parse();
echo phpversion();

?>

Produces the following error:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/8/d335242830/htdocs/caseyflynn/php/display_formatted_RSS_feed.php on line 3

As far as I can tell I have the correct syntax. My server is running PHP 4.5. Any ideas?

1 Answer 1

4

My server is running PHP 4.5

This is your problem: PHP 4 doesn't know the public keyword - along with a heap of other OOP features.

As @konforce says, in the code you show, you can simply switch to using the var keyword. But the best thing would really be to switch to PHP 5. PHP 4's time is really, really over.

Sign up to request clarification or add additional context in comments.

2 Comments

You can replace public with var, but Pekka's advice still remains true.
Thanks guys, I normally work with PHP5 anyways but this is for a class and my professor has some odd reasons for sticking with PHP4 on his private web server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.