'Cannot declare class ComposerAutoloaderInit

I have a question i have an error im not enabled to fix. The error is saying the name is already in use. What im trying to do is im calling a API that needs to give some response back. Because of this error im not enabled to acces the data of my API

The Error

Cannot declare class ComposerAutoloaderInitd1e500cc63b56a87596c43fefa8d9495, because the name is already in use in

This is my autoload.php

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitd1e500cc63b56a87596c43fefa8d9495::getLoader();

autoload_real.php

<?php

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitd1e500cc63b56a87596c43fefa8d9495
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        spl_autoload_register(array('ComposerAutoloaderInitd1e500cc63b56a87596c43fefa8d9495', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
        spl_autoload_unregister(array('ComposerAutoloaderInitd1e500cc63b56a87596c43fefa8d9495', 'loadClassLoader'));

        $includePaths = require __DIR__ . '/include_paths.php';
        $includePaths[] = get_include_path();
        set_include_path(implode(PATH_SEPARATOR, $includePaths));

        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
        if ($useStaticLoader) {
            require_once __DIR__ . '/autoload_static.php';

            call_user_func(\Composer\Autoload\ComposerStaticInitd1e500cc63b56a87596c43fefa8d9495::getInitializer($loader));
        } else {
            $map = require __DIR__ . '/autoload_namespaces.php';
            foreach ($map as $namespace => $path) {
                $loader->set($namespace, $path);
            }

            $map = require __DIR__ . '/autoload_psr4.php';
            foreach ($map as $namespace => $path) {
                $loader->setPsr4($namespace, $path);
            }

            $classMap = require __DIR__ . '/autoload_classmap.php';
            if ($classMap) {
                $loader->addClassMap($classMap);
            }
        }

        $loader->register(true);

        return $loader;
    }
}



Solution 1:[1]

I had this issue when including two composer autoloaders from two directories where one originated as a copy of the other one (don't ask me why).

Based on this GitHub Issue I concluded my solution:

Delete the composer lock-file (e.g. composer.lock) and execute composer update.

In my case I just deleted the vendor-directory too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leander Hass