我遇到了一个脚本,用于显示我博客帐户中最后X个博客帖子的数量,但是我收到了这个警告:
警告:不推荐使用call-time pass-by-reference - 按值传递的参数;如果您想通过引用传递它,请修改xml_set_object()的声明。如果要启用调用时传递引用,可以在INI文件中将allow_call_time_pass_reference设置为true。但是,未来版本可能不再支持此功能。在第88行的test.php中
以下是代码:
<div id="latestentries">
<ul id="entrieslist">
<?php
class RSSParser {
var $insideitem = false;
var $tag = "";
var $title = "";
var $pubDate = "";
var $link = "";
var $thr = "";
var $counter = 1;
function startElement($parser, $tagName, $attrs) {
if ($this->insideitem) {
$this->tag = $tagName;
} elseif ($tagName == "ITEM") {
$this->insideitem = true;
}
}
function endElement($parser, $tagName) {
if ($this->counter < 5) {
if ($tagName == "ITEM") {
$title = htmlspecialchars(trim($this->title));
if (strlen($title) > 35) {
if ($this->thr > 0) {
$name = $title;
$name = $name . " ";
$name = substr($name,0,31);
$title = $name . " ...";
}
if (strlen($title) > 45) {
if ($this->thr == 0) {
$name2 = $title;
$name2 = $name2 . " ";
$name2 = substr($name2,0,41);
$title = $name2 . "...";
}
}
}
$date = htmlspecialchars(trim($this->pubDate));
$pubDate = substr($date,0,str_length-20) . ".";
printf("<li class='entry'><a href='%s'><span class='entrydate'>%s</span><span>%s</span>",trim($this->link),$pubDate,$title);
if ($this->thr == 1) { printf("<span class='entrycomments'>(%s Comment)</span>",$this->thr); }
elseif ($this->thr > 1) { printf("<span class='entrycomments'>(%s Comments)</span>",$this->thr); }
echo "</a></li>";
$counter = $this->counter;
$this->counter = $counter + 1;
$this->title = "";
$this->pubDate = "";
$this->link = "";
$this->thr = "";
$this->insideitem = false;
}
}
}
function characterData($parser, $data) {
if ($this->insideitem) {
switch ($this->tag) {
case "TITLE":
$this->title .= $data;
$this->counter .= $counter;
break;
case "PUBDATE":
$counter++;
$this->pubDate .= $data;
break;
case "LINK":
$counter++;
$this->link .= $data;
break;
case "THR:TOTAL":
$counter++;
$this->thr .= $data;
break;
}
}
}
}
$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("rss.xml","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
?>
</ul>
</div>
有人可以帮我关掉警告,还是告诉我如何修复它? :)
答案 0 :(得分:1)
摆脱“&amp;”在$ rss_parser中:
xml_set_object($xml_parser,&$rss_parser);
变为: xml_set_object($ xml_parser,$ rss_parser);
根本不需要通过引用传递对象。它在这个版本的PHP中是自动的。
雅各