【问题标题】:Getting deprecated error with Simplepie使用 Simplepie 出现不推荐使用的错误
【发布时间】:2012-02-26 20:05:46
【问题描述】:

我已经安装了最新的 Simplepie 代码 (1.2.1),我正在使用他们提供的演示代码:

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

有人知道怎么回事吗?

我进行了他们的兼容性测试,结果表明一切都通过了。

【问题讨论】:

标签: rss simplepie


【解决方案1】:

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

error_reporting(E_ALL & ~E_DEPRECATED);

如果您想自己修复错误,您可以从GitHub 获取一份 SimplePie 1.3-dev(它会降低 PHP 4 兼容性),但请记住,这是一个开发版本并且不稳定。

【讨论】:

  • 这是正确答案。另见WP bug database。 Simplepie 可能在此期间进行了调整,但即比较修订版仍然不与 WP 3.4.2 ......所以仍然必须静音已弃用的警告。至少用于生产。
  • WordPress 3.5 将包含 SimplePie 1.3.1,它已修复所有这些问题(因为它放弃了 PHP 4 支持)。
【解决方案2】:

我在 1.2.1 版中唯一能找到的 error_reporting 是这一行:

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

这是在 simplepie.inc 中

我仍然不确定如何禁用所有这些警告,而不是使用我不希望使用的开发版本,因为我有足够的代码可以按原样调试。

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      相关资源
      最近更新 更多