Laravel Facade类错误 - 不应静态调用非静态方法

时间:2014-04-02 20:29:23

标签: php laravel

这是我得到的错误:

Non-static method Tester\Test::echoString() should not be called statically, assuming $this from incompatible context

以下是我添加到app.php的内容:

的ServiceProvider:

"Tester\TestServiceProvider"

和Alias:

"Test" =>  "Tester\Test"

这是我的主要课程。 named:test.library.php:

namespace Tester;

class Test 
{
    function echoString()
    {
        echo "This is a text string";
    }

    function printer($input)
    {
        $this->echoString();
        echo " $input";
    }
}

这是我的test.facade.php文件:

class Test extends \Illuminate\Support\Facades\Facade
{
    protected static function getFacadeAccessor() { return 'Test'; }
}

这是test.serviceprovider.php类:

use Illuminate\Support\ServiceProvider;

class TestServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind('Test', function()
        {
            return new \Tester\Test(); // Name of your class, be sure to include the namespace if you are using one.
        });
    }
}

1 个答案:

答案 0 :(得分:4)

我认为这是因为你有一个名为Test的类,还有一个名为Test的Facade。这是名称空间的冲突。

..可能将Test(外观)重命名为TestFacade,然后将别名设置为“Test”=> “测试\ TestFacade”