tags:

views:

98

answers:

1

hi all, I came across a script to display the last X amount of blog posts from my blogger account, however I'm getting this warning:

Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in test.php on line 88

Here's the code:

<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>

Could someone help me turn off the warning, or show me how to fix it? :)

+1  A: 

Get rid of the "&" in $rss_parser:

xml_set_object($xml_parser,&$rss_parser);

Becomes: xml_set_object($xml_parser,$rss_parser);

Passing the object by reference should not be needed at all. It is automatic in this version of PHP.

Jacob

TheJacobTaylor
Thank you, that worked.. (feels stupid now) lol
SoulieBaby
You would not if you have seen the code that I have seen. :)
TheJacobTaylor
I'm sure lol Thank you for your help though, muchly appreciated! :)
SoulieBaby