13

I'm actually upgrade my symfony 3.4 project to symfony 4.0. After clone bundles from my gitlab repositories with composer update, I have an error :

ClassNotFoundException

Attempted to load class "Kernel" from namespace "App".
Did you forget a "use" statement for "Symfony\Component\HttpKernel\Kernel"?


in index.php (line 32)

Ok.... Easy... go index.php line 32... but, Kernel is load with App\Kernel, so any idea why I have this error or where I can search?

Thank you for your help.

index.php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    (new Dotenv())->load(__DIR__.'/../.env');
}

if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
    umask(0000);

    Debug::enable();
}


    // Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED);

$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

And in the "src" directory, I have the Kernel.php file

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
    .....
15
  • Guessing you still have AppBundle instead of App in your composer.json psr4 section. Commented Dec 26, 2017 at 18:20
  • No. I have the good path, "": "src/" Commented Dec 26, 2017 at 18:23
  • 2
    And you ran composer dump-autoload? Commented Dec 26, 2017 at 18:24
  • Yes. Nothing same error. Commented Dec 26, 2017 at 18:27
  • 2
    PSR4 autoload for Sym4 is App\\": "src/" Commented Dec 27, 2017 at 3:33

2 Answers 2

6

Maybe you just accidentially removed the PSR-4 block in composer.json that is always needed for Symfony4:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
Sign up to request clarification or add additional context in comments.

Comments

5

Symfony 4 uses the folder App for autoload psr-4. I tried to change it, but it didn't work out. Check the namespace at your composer.json file, in the property autoload and then psr-4. Maybe you changed the default one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.