gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:31:40 27 4
gpt4 key购买 nike

这是我得到的错误:

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

这是我添加到 app.php 中的内容:

服务提供者:

"Tester\TestServiceProvider"

还有别名:

"Test" =>  "Tester\Test"

这是我的主要类(class)。命名: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.
});
}
}

最佳答案

我认为这是因为您有一个名为 Test 的类和一个名为 Test 的 Facade。这是命名空间上的冲突。

.. 可能将 Test(外观)重命名为 TestFacade,然后将别名设置为 "Test"=> "Tester\TestFacade"

关于php - Laravel Facade 类错误 - 不应静态调用非静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822341/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com