Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP对象属性声明错误_Php - Fatal编程技术网

PHP对象属性声明错误

PHP对象属性声明错误,php,Php,我在创建的PHP类中定义属性时遇到了一些问题 <?php class news_parser { public $var1 = Array(); function contents($parser, $data) { printf($data); } function start_tag($parser, $data, $attribs) { printf($data); } function end_tag(

我在创建的PHP类中定义属性时遇到了一些问题

<?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();

?>
据我所知,我有正确的语法。我的服务器正在运行PHP4.5。有什么想法吗

我的服务器正在运行PHP4.5

这就是你的问题:PHP4不知道
public
关键字,还有一堆

正如@konforce所说,在您显示的代码中,您可以简单地切换到使用
var
关键字。但最好的办法是切换到PHP5。PHP4的时代真的,真的结束了

我的服务器正在运行PHP4.5

这就是你的问题:PHP4不知道
public
关键字,还有一堆


正如@konforce所说,在您显示的代码中,您可以简单地切换到使用
var
关键字。但最好的办法是切换到PHP5。PHP4的时代真的,真的结束了。

你可以用
var
代替
public
,但佩卡的建议仍然是正确的。谢谢大家,无论如何,我通常使用PHP5,但这是为了上课,我的教授有一些奇怪的理由坚持在他的私人网络服务器上使用PHP4。你可以用
var
替换
public
,但佩卡的建议仍然是正确的。谢谢大家,无论如何,我通常使用PHP5,但这是为了上课,我的教授有一些奇怪的理由坚持在他的私有web服务器上使用PHP4。
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