Strict Standards: Non-static method

白昼怎懂夜的黑 提交于 2019-12-24 05:47:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!