2012-02-04 88 views
3

我已经安装了最新的代码了SimplePie(1.2.1),我使用他们提供的演示代码:获取废弃的错误使用了SimplePie

<?php 

require 'simplepie.inc'; 

$url = 'http://news.google.com/news?ned=us&topic=h&output=rss'; 

$feed = new SimplePie(); 
$feed->set_feed_url($url); 
$feed->init(); 

// default starting item 
$start = 0; 

// default number of items to display. 0 = all 
$length = 0; 

// if single item, set start to item number and length to 1 
if(isset($_GET['item'])) 
{ 
    $start = $_GET['item']; 
    $length = 1; 
} 

// set item link to script uri 
$link = $_SERVER['REQUEST_URI']; 

// loop through items 
foreach($feed->get_items($start,$length) as $key=>$item) 
{ 

    // set query string to item number 
    $queryString = '?item=' . $key; 

    // if we're displaying a single item, set item link to itself and set query string to nothing 
    if(isset($_GET['item'])) 
    { 
      $link = $item->get_link(); 
      $queryString = '';   
    } 

    // display item title and date  
    echo '<a href="' . $link . $queryString . '">' . $item->get_title() . '</a>'; 
    echo ' <small>'.$item->get_date().'</small><br>'; 

    // if single item, display content 
    if(isset($_GET['item'])) 
    { 
      echo ' <small>'.$item->get_content().'</small><br>'; 
    } 
    echo '<br>'; 
} 

?> 

然而,当我加载页面在浏览器中,我得到几十条线说:

Deprecated: Assigning the return value of new by reference is deprecated in /home/pliggs/public_html/rss/simplepie.inc on line 7722 

任何人都知道什么是错的?

我跑他们的兼容性测试,它显示所有的东西都过去了。

+1

[指定新引用的返回值已被弃用]的可能重复(http://stackoverflow.com/questions/1086539/assigning-the-return-value-of-new-by-reference-is-deprecated ) – geoffspear 2012-02-04 14:51:27

回答

2

这是SimplePie的PHP 4兼容性的结果,在您的代码中没有任何东西。如果你不想看到这些错误,从error_reporting排除E_DEPRECATED

error_reporting(E_ALL & ~E_DEPRECATED); 

如果你想修复错误本身,你可以抓住1.3了SimplePie-dev的复印件(其下降PHP 4的兼容性)从GitHub,虽然请记住这是一个开发版本,并且不稳定。

+0

这是正确的答案。另见[WP bug数据库](http://core.trac.wordpress.org/ticket/12709)。 Simplepie可能在此期间进行了调整,但比较修订版仍然不适用于WP 3.4.2 ...,因此仍然需要禁用不推荐使用的警告。至少用于生产。 – 2012-11-14 10:06:45

+0

WordPress 3.5将包含SimplePie 1.3.1,它具有所有这些固定功能(因为它支持PHP 4)。 – 2012-11-14 10:12:02

0

的error_reporting唯一的发生,我能找到在1.2.1版本是这条线:

if ((ini_get('error_reporting') & $level) > 0) 

这是simplepie.inc

我仍然不知道如何禁用所有这些警告因为我有足够的代码来进行调试,所以不愿意使用开发版本。

2

您需要在代码中找到“= &新”的每个实例,并删除现已弃用的“&”。代码中大约有116次出现。它与对象实例化的副本和引用有关。