laravel 致命错误:未捕获的反射异常:类配置不存在

7tofc5zh  于 2023-05-23  发布在  其他
关注(0)|答案(9)|浏览(122)

我正在Laravel 5.8上做一个电子商务项目,但是由于我不小心在项目的文件夹上运行了“laravel new”命令,当我试图在本地服务器上启动项目时,我得到了这个错误:
致命错误:未捕获的反射异常:Copyright © 2018 - 2019 www.wamp64.com版权所有Copyright © 2018 www.wamp64.com版权所有Copyright © 2018 - 2019 www.wamp64.com版权所有Copyright © 2016 - 2018 www.jsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsj C:\wamp64\www\e-commerce\vendor\laravel\framework\src\Illuminate\Foundation\Application. php(767):\\\\\\\\\\\\\框架\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Copyright © 2018 - 2019 www.jsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsjsj
第788行上的错误指的是代码的这一部分:

$reflector = new ReflectionClass($concrete)

这是在我从Github克隆了我的repo之后发生的。现在,对于我尝试在本地服务器上运行的每个项目,我都会得到此错误。
我尝试了"composer install","composer update","composer dump-autoload",但它们都在最后给出了相同的错误:"Script@php artisan package:discover--ansi handling the post-autoload-dump event returned with error code 255".
我检查了. env文件,看看是否也有名称空间问题,但没有。
提前感谢您的帮助。

30byixjq

30byixjq1#

尝试删除文件在:

cd bootstrap/cache/
rm -rf *.php

在这个目录中是初始化结构的文件,缓存目录中包含结构生成的用于性能优化的文件,如文件和路由缓存服务。

k4ymrczo

k4ymrczo2#

你可以检查下列项目
1.检查您的APP_NAME是否有空间。如果有空格,用引号。
1.删除bootstrap/cache/ folder中的所有内容。
1.运行composer dump-autoload
希望能成功

zte4gxcn

zte4gxcn3#

我尝试了@gulCunha的答案,它奏效了。
在此之后,您必须运行composer update以创建一个新的composer.lockphp artisan config:cache,您应该可以运行。

iszxjhcz

iszxjhcz4#

你改变了 .env 文件,错误地我添加了一个"APP_NAME=aaa aa "与空格,然后检查每一个地方,之后,APP_NAME=改变没有空格,现在工作魅力。

628mspwn

628mspwn5#

我用composer创建了一个新的Laravel 9项目,得到了同样的错误。

Fatal error: Uncaught ReflectionException: Class "config" does not exist in .../vendor/laravel/framework/src/Illuminate/Container/Container.php:875
Stack trace:
#0 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(875): ReflectionClass->__construct('config')
#1 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config')
#2 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true)
#3 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array)
#4 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array)
#5 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config')
#6 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config')
#7 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver()
#8 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL)
#9 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(702): Illuminate\Log\LogManager->driver()
#10 .../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(274): Illuminate\Log\LogManager->log('error', 'substr(): Argum...', Array)
#11 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(367): Illuminate\Foundation\Exceptions\Handler->report(Object(TypeError))
#12 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException(Object(TypeError))
#13 .../artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 {main}

Next Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist. in .../vendor/laravel/framework/src/Illuminate/Container/Container.php:877
Stack trace:
#0 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config')
#1 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true)
#2 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array)
#3 .../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array)
#4 .../vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config')
#5 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config')
#6 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver()
#7 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL)
#8 .../vendor/laravel/framework/src/Illuminate/Log/LogManager.php(702): Illuminate\Log\LogManager->driver()
#9 .../vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(274): Illuminate\Log\LogManager->log('error', 'substr(): Argum...', Array)
#10 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(367): Illuminate\Foundation\Exceptions\Handler->report(Object(TypeError))
#11 .../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Foundation\Console\Kernel->reportException(Object(TypeError))
#12 .../artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main}
  thrown in .../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 877
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

但这一次不是该高速缓存。不管这些错误表明了什么,问题实际上是由vendor/vlucas/phpdotenv/src/Util/Str.php中的以下行引起的

$converted = $encoding === null ?                                             
    @\mb_convert_encoding($input, 'UTF-8') :                                  
    @\mb_convert_encoding($input, 'UTF-8', $encoding);

实际上,当我构建PHP二进制文件时,我没有启用Multibyte String。在用--enable-mbstring重建PHP之后,这个问题就消失了。

w8f9ii69

w8f9ii696#

确保您的.env文件与本地环境中的文件完全相同。确保.env文件中的值没有空格。那些有空格的应该用引号括起来

9udxz4iz

9udxz4iz7#

我也遇到过类似的问题。这就是我如何修复它。
它是在我的config/app.php提供程序中安装Toastr时开始的。我没能加上结尾的“,”。这就是问题所在。
解决方案:检查您安装的最后一个软件包。检查您是否在服务提供商中正确添加了它。

ua4mk5z4

ua4mk5z48#

你应该运行'composer update'命令,然后'php artisan optimize'来清除配置缓存和路由。

oymdgrw7

oymdgrw79#

如果您在将Lumen 5.8 Web应用程序迁移到Laravel 5.8时遇到此错误,在运行php vendor/bin/phpunit时,请检查main Test\TestCase是否在类主体中有use CreatesApplication;,而不是它自己的function createApplication()

abstract class QdtTestCase extends BaseTestCase
{
    use CreatesApplication;

    /**
//     * Creates the application.
//     *
//     * @return Application
//     */
//    public function createApplication()
//    {
//        return require __DIR__ . '/../bootstrap/app.php';
//    }
}

您可以从一个新的Laravel 5.8项目中复制这个Test\CreatesApplication.php文件。
或者,你可以写:

abstract class QdtTestCase extends BaseTestCase
{
    // use CreatesApplication;

    /**
     * Creates the application.
     *
     * @return Application
     */
    public function createApplication()
    {
        $app = require __DIR__ . '/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }
}

ReflectionException:调用config('database.default')时,在\Illuminate\Foundation\Testing\RefreshDatabase::usingInMemoryDatabase内部发生“Class config does not exist”错误,调用config('app.url')时,在\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::prepareUrlForRequest内部发生“Class config does not exist”错误。

相关问题