Php Facades:不应静态调用非静态方法
我创建了一个类和外观,如下所示: Invoice.php(Facades/Invoice.php) 并调用testfunc方法:Php Facades:不应静态调用非静态方法,php,laravel,laravel-5,Php,Laravel,Laravel 5,我创建了一个类和外观,如下所示: Invoice.php(Facades/Invoice.php) 并调用testfunc方法: dd(Invoice::testfunc()); 在app.php中,我添加了以下(提供者):app\providers\InvoiceFacadesServiceProvider::class, 和(别名):'invoice'=>App\Facades\invoice::class, 但我只得到: Non-static method App\Invoice\Inv
dd(Invoice::testfunc());
在app.php
中,我添加了以下(提供者):app\providers\InvoiceFacadesServiceProvider::class,
和(别名):'invoice'=>App\Facades\invoice::class,
但我只得到:
Non-static method App\Invoice\Invoice::testfunc() should not be called statically.
我还注意到,getFacadeAccessor()
方法从未被触发,因为它没有命中我放在那里的dd
我错过了什么
谢谢你的帮助和指导 您调用类
Invoice
,而不是FacaceInvoice
。这就是为什么会出现警告
尝试调用
\App\Facades\Invoice::testfunc()
,然后通过facade调用该方法。调用类Invoice
,而不是FacaceInvoice
。这就是为什么会出现警告
尝试调用
\App\Facades\Invoice::testfunc()代码>,然后通过facade调用该方法。从该函数中删除static。从该函数中删除static。
<?php
namespace App\Invoice;
class Invoice
{
public function testfunc()
{
return "This is a test";
}
}
?>
use App\Invoice\Invoice;
dd(Invoice::testfunc());
Non-static method App\Invoice\Invoice::testfunc() should not be called statically.