为什么php5可以找到我的类,但php7不能?

时间:2016-12-06 13:40:46

标签: laravel namespaces php-7 classnotfound

我有一个基于Laravel 5.2的应用程序,它使用的是php 5.6,我决定将我的应用程序移动到php7(主要是为了性能优势)会很棒。一切似乎都很好,除了php7在我的应用程序中找不到一个特定的类。

该文件存储在app / Libraries / Main / Google / Auth / Auth.php文件中,它有一个名称空间Google和一个类名GoogleAuth,因此每次我想使用它时,我只是把 - 使用Google / GoogleAuth;在文件的顶部。在php5中这很好用,但在php7中找不到类。这可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我认为仍然是一步,运行composer dump-autoloadphp artisan clear-compiled 命令。可能是这个命令会解决这个问题。

<强>更新

"autoload": {
    "classmap": [
        "database", 
        "app/Libraries/Main"
    ],
    "psr-4": {
        "App\\": "app/"
    }
}

使用上述代码更新composer.json后,请运行以下命令:

//To clears all compiled files.
php artisan clear-compiled 

//To updates the autoload_psr4.php
composer dump-autoload

//updates the autoload_classmap.php
php artisan optimize