Peter
Peter

Reputation: 155

Strict Standards: Non-static method

I'm running Ubuntu + PHP 5.4 and got such error:

Strict Standards: Non-static method XTemplate::I() should not be called statically, assuming $this from incompatible context in ... on line 339

And that method looks like this:

interface ITemplate
{
    public function I();
}

class XTemplate implements ITemplate
{
    public function I()
    {
             ...
    }
}

And this code is running normal on Windows 7 in XAMPP. I have found only advices to turn off error_reporing, but I need to solve it. Do I need to install some modules on turn on some other settings in php.ini ?

Upvotes: 1

Views: 9496

Answers (2)

Marcin
Marcin

Reputation: 323

I had same error, all you need is a change in Interface: public function I(); change to public static function I(); and when you create instance use

public static function I();

I hope this help.

Upvotes: -1

1615903
1615903

Reputation: 34733

You are getting the error message because you are calling the function statically instead of creating an instance of XTemplate class. Depending on your situation, either make the function static:

static public function I()
    {
             ...
    }

Or first create an instance of XTemplate:

$myXtemplate = new XTemplate();
$myXtemplate->I();

I hope this answers your question.

Edit: This page may be interesting to you.

Upvotes: 4

Related Questions