【问题标题】:Strict Standards: Declaration of API_RATING::multiDelete() should be compatible with API::multiDelete($ids = 0)严格标准:API_RATING::multiDelete() 的声明应该与 API::multiDelete($ids = 0) 兼容
【发布时间】:2013-10-07 11:58:48
【问题描述】:

我最近将我的一个站点移到了运行最新版本 PHP 的新专用服务器上。在我网站的基于 php 的知识库部分中,我收到以下错误:

严格标准:API_RATING::multiDelete() 的声明应与第 156 行 /home/givebrad/public_html/kb/lib/api/class.rating.php 中的 API::multiDelete($ids = 0) 兼容

第 156 行是文件底部的最后一个结束 }。下面是 class-rating.php 的代码。谁能帮我弄清楚如何解决这个问题?

<?php
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class.api.php');

class API_RATING extends API
{
    var $rateid = 0;
    var $questionid = 0;
    var $ip = '';
    var $ratedat = '';

    var $fields = array (
        'rateid',
        'questionid',
        'ip',
        'ratedat',
        'ratingemail',
        'ratingmessage'
    );

    var $pk = 'rateid';

    /**
    * create
    * create a new rating in the database
    *
    * @return bool was the creation successful ?
    */
    function create()
    {
        $_POST['ratedat'] = date('Y-m-d H:i:s');
        $_POST['ip'] = $_SERVER['REMOTE_ADDR'];
        return parent::create();
    }

    /**
    * multiDelete
    * Delete multiple rating ids. Update each associated question.
    *
    * @return bool was the delete successful?
    */
    function multiDelete($ids) {

        //Get the question ids
        $objArray = $this->loadMultiByPK($ids);

        foreach ($objArray as $rateObj) {
            $questionObj = new API_QUESTION(); 
            $questionObj->load($rateObj->questionid);

            $questionObj->negvotes--;
            $questionObj->score -= SCORE_MODIFIER;

            $questionObj->updateField("negvotes", $questionObj->negvotes);
            $questionObj->updateField("score", $questionObj->score);
        }           

        //Delete from the main table
        if (!parent::multiDelete($ids)) {
            return false;
        }

        return true;
    }

    /**
    * validate_rateid
    *
    * Ensure the rate id is a pos int
    *
    * @param string $var
    *
    * @return bool
    */
    function validate_rateid($var)
    {
        return $this->is_positive_int($var);
    }

    /**
    * validate_questionid
    *
    * Ensure the questionid is pos int
    *
    * @return bool
    */
    function validate_questionid($var)
    {
        return $this->is_positive_int($var);
    }

    /**
    * validate_ip
    *
    * Ensure the ip is an ipv4 address
    *
    * @param $var the ip to validate
    *
    * @return bool
    */
    function validate_ip($var)
    {
        return $this->is_ip($var);
    }

    /**
    * validate_ratedat
    *
    * Ensure the rated at date is in the standard date format
    *
    * @param string $var
    *
    * @return bool
    */
    function validate_ratedat($var)
    {
        return $this->is_standard_date($var);
    }

    /**
    * validate_email
    *
    * Ensure the email address for this rate entry is valid.
    *
    * @param string $var
    *
    * @return bool
    */
    function validate_ratingemail(&$var)
    {
        if ((trim($var) == "") || (trim($var) == GetLang("WhyUnhelpfulEmail"))) {
            $var = "";
            return true;
        } else {
            return is_email_address($var);
        }
    }   

    /**
    * validate_ratingmessage
    *
    * Ensure there is a message and its not blank.
    *
    * @param string $var
    *
    * @return bool
    */
    function validate_ratingmessage(&$var)
    {
        if (strlen(trim($var)) > 250) {
            $var = substr(trim($var),0,250);
            return true;
        } else {
            return (trim($var) != "");
        }
    }
}

?>

【问题讨论】:

  • 没有什么要弄清楚的——你的方法签名是($id),而你继承的API类的方法参数定义为($ids = 0)。因此,只需调整您的方法以设置该默认值,以便签名再次匹配。

标签: php data-structures


【解决方案1】:

这个功能:

function multiDelete($ids) {

应该和它的父函数相同,在API类中找出相同的函数,参数的数量、默认值和类型应该相同;

我之前问过这个问题,Strict Standards: Declaration of ' ' should be compatible with ' '

【讨论】:

    猜你喜欢
    • 2014-02-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    相关资源
    最近更新 更多