问题
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 ?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/15897797/strict-standards-non-static-method