2

我尝试用我的新类扩展 CheckfrontAPI 类。

在我的情况下,我使用单例模式来一次只加载一个实例,我得到了那个错误

致命错误:CheckFrontIntegrator::store() 的声明必须与第 83 行 /home/my_web_site/public_html/wp-content/plugins/checkfront/class/Checkfront_Integration.php 中的 CheckfrontAPI::store() 的声明兼容

关于如何解决该问题的任何想法?

这是 CheckfrontAPI 源代码:https ://github.com/Checkfront/PHP-SDK/blob/master/lib/CheckfrontAPI.php

这是我的类扩展该类:

<?php

class CheckFrontIntegrator extends CheckfrontAPI
{
    private static $instance = null;
    public $tmp_file = '.checkfront_oauth';

    final protected function store($data = array())
    {
        $tmp_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR. $this->tmp_file;

        if(count($data))
        {
            file_put_contents(  
                $tmp_file,
                json_encode(
                    $data, 
                    true
                )
            );
        }
        elseif(is_file($tmp_file))
        {
            $data = json_decode(
                trim(
                    file_get_contents(
                        $tmp_file
                    )
                ),
                true
            );
        }

        return $data;
}

    public function session($session_id, $data = array())
    {
        $_SESSION['checkfront']['session_id'] = $session_id;
}

    public static function instance($data)
    {
        if(!isset(self::$instance))
        {
            self::$instance = new CheckFrontIntegrator($data);
        }

        return self::$instance;
    }

    public function __construct($data)
    {
        if(session_id() == '')
        {
            session_start();
        }

        parent::__construct($data, session_id());
    }
}

?>

我像这样启动该类的新实例:

$this->checkfront_integrator = CheckFrontIntegrator::instance($args);

其中 args 是类启动新对象所需的所有重要信息

编辑后

我已经从以下位置更改了我的方法存储:

final protected function store($data = array())
....

protected function store($data)
....

并且问题仍然存在:(

4

3 回答 3

3

CheckfrontAPI 是一个抽象类?在这种情况下,您的 CheckFrontIntegrator::store() 参数计数必须与原始声明相同

编辑

我在github上看到

abstract protected function store($data);

您的覆盖必须是:

protected function store($data) {

}
于 2012-04-06T07:15:03.160 回答
2

您正在扩展 CheckfrontAPI。CheckfrontAPI 有一个方法 store()。如果您覆盖该方法,则必须正确执行。

贴出 CheckfrontAPI 和你的类 Checkfront_Integration 的代码:什么时候能明白什么问题。

于 2012-04-06T07:14:39.727 回答
1

当您想通过编写自己的类来扩展现有类的功能并且您要扩展的类是抽象类时,您需要确保函数调用是兼容的。
这是什么意思?

如果您要扩展的类具有此函数调用,例如:

function walk($direction, $speed = null);

然后你必须在你的实现中尊重函数签名——这意味着你仍然必须在你的版本中传递两个函数参数。

你将无法改变是这样的:

function walk($direction, $speed, $clothing);
于 2012-04-06T07:24:14.360 回答