2

I try to extend the CheckfrontAPI class with my new class.

In my case I use the Singleton pattern in order to load only one instance at a time of my class and I get that error

Fatal error: Declaration of CheckFrontIntegrator::store() must be compatible with that of CheckfrontAPI::store() in /home/my_web_site/public_html/wp-content/plugins/checkfront/class/Checkfront_Integration.php on line 83

Any idea on how to solve that issue ?

Here is the CheckfrontAPI source code : https://github.com/Checkfront/PHP-SDK/blob/master/lib/CheckfrontAPI.php

And here is my class that extends that class:

<?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());
    }
}

?>

And I initiate the new instance of that class like that:

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

where args are all the important information needit by the class to initiate a new object

AFTER EDIT

I have change my method store from:

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

to

protected function store($data)
....

and the problem still occure :(

7
  • 1
    Do the number and types of parameters match? (Between both store() member functions.)
    – wallyk
    Apr 6, 2012 at 7:12
  • 1
    can you paste the full error you are getting after modification Apr 6, 2012 at 7:36
  • 1
    Your method store should look like: protected function store($data)! You already solve the problem by yoursefl with method session. In your class: public function session($session_id, $data = array()), int the class you extend from: abstract public function session($session_id,$data);
    – ab_dev86
    Apr 6, 2012 at 7:37
  • 1
    @Merianos Nikos. Actually i run your code whithout errors. I'am sospicius about how you instantiate your class: $this->checkfront_integrator = CheckFrontIntegrator::instance($args); what is the preciding code? which object is $this?
    – ab_dev86
    Apr 6, 2012 at 7:57
  • 1
    @ab_dev86 The problem solved. Was cache issue. Also in my local web server the code run with no issue. But on HostGator servers I had the issue. Thanks a lot for your assistance and you time !!
    – KodeFor.Me
    Apr 6, 2012 at 7:58

3 Answers 3

3

CheckfrontAPI is an abstract class? in this case your CheckFrontIntegrator::store() arguments count must be identical to original declaration

EDIT

I see on github

abstract protected function store($data);

your override must be:

protected function store($data) {

}
3
  • I made that change and the problem still occure. Any idea ?
    – KodeFor.Me
    Apr 6, 2012 at 7:26
  • 2
    Have you some cache somewhere? Apr 6, 2012 at 7:46
  • 1
    Ok note that also final protected function store($data = array()) is legal!
    – ab_dev86
    Apr 6, 2012 at 7:58
2

You are extending CheckfrontAPI. CheckfrontAPI has a method store(). If you override that method you must do it properly.

Post the code of CheckfrontAPI and your class Checkfront_Integration: when can understand what's the problem.

1

When you want to extent the functionality of an existing class by writing your own class and the class you are extending is is an abstract one, you'll need to make sure that the function calls are compatible.
What does this mean?

If the class you are extending has this function call for example :

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

Then you will have to honor the function signature in your implementation - that means you'll still have to have to pass two function arguments in your version.

You will not be able to alter is to be like this :

function walk($direction, $speed, $clothing);
1
  • I know that, but if you see my code above, I have the store method in my class with excact arguments, and still get that error :(
    – KodeFor.Me
    Apr 6, 2012 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.