Autoloader expected class Symfony2

I'm using symfony 2.3 framework and the autoloader claims to have found the file but no class:

RuntimeException: The autoloader expected class "Sensio\Bundle\
FrameworkExtraBundle\Request\ParamConverter\DateTimeParamConverter" 
to be defined in file "/home/na/auth/vendor/sensio/framework-extra-bundle/
Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/
DateTimeParamConverter.php". The file was found but the class was not in it, 
the class name or namespace probably has a typo.

The file this is refering to is shown bellow:

<?php

/*
 * This file is part of the Symfony framework.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use DateTime;

/**
 * Convert DateTime instances from request attribute variable.
 *
 * @author Benjamin Eberlei <kontakt@beberlei.de>
 */
class DateTimeParamConverter implements ParamConverterInterface
{
    /**
     * @{inheritdoc}
     * 
     * @throws NotFoundHttpException When invalid date given
     */
    public function apply(Request $request, ConfigurationInterface $configuration)
    {
        $param = $configuration->getName();

        if (!$request->attributes->has($param)) {
            return false;
        }

        $options = $configuration->getOptions();
        $value   = $request->attributes->get($param);

        $date = isset($options['format'])
            ? DateTime::createFromFormat($options['format'], $value)
            : new DateTime($value);

        if (!$date) {
            throw new NotFoundHttpException('Invalid date given.');
        }

        $request->attributes->set($param, $date);

        return true;
    }

    /**
     * @{inheritdoc}
     */
    public function supports(ConfigurationInterface $configuration)
    {
        if (null === $configuration->getClass()) {
            return false;
        }

        return "DateTime" === $configuration->getClass();
    }
}

Anyway, some detail that might help was that I recently installed Doctrine and ran the commands ...

 2028  php app/console doctrine:schema:create
 2029  php app/console doctrine:generate:entities Auth

After those commands, symfony stopped working. I don't know if this is some weird bug or something. If you need more information, I can post. Thanks for any help.

Answers


Missing (or short) PHP opening tag can cause that error too. Yes it sounds funny, but if you just follow Symfony example and copy/paste whole class you may not notice that (as I didn't).


This is a little old now, but in case anyone else gets here by search: This is undoubtedly a cache issue. Manually delete the contents of app/cache/dev and app/cache/prod, and everything should resolve.


If anyone else has this issue and it doesn't go away by clearing the cache, then I recommend removing the entire folder with your composer dependencies and re-executing composer install.

It worked for me :) .


I think there's a bug in Symfony2. They recently updated to a new version (2.3.1) of symfony, which I think must of broke something. Anyway, I had to comment out //new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle() line in the AppKernel.php file to get rid of the error.


Be certain that your namespace is defined in the class that you are trying to use. For instance, in my controller I had:

use Acme\DemoBundle\Amazon\AmazonProductAPI;

This was the correct path to my AmazonProductAPI class, but the system didn't recognize it until I added the proper namespace to the class:

namespace Acme\DemoBundle\Amazon;

Answer of @MilanG helped me! I switched my PHP configuration from

short_open_tag = Off

to

short_open_tag = On

I resolved this issue by removing an extra \ before Doctrine as in:

 <entity repository-class="ACC\Bundle\MGLBundle\\\Doctrine\ORM\PersonRepository" 
         name="ACC\Bundle\MGLBundle\Entity\Person" >`

I used the generate:doctrine:entity utility to make the entity as well as the orm.xml file. This utility seems to have a bug and it adds an extra \ in the xml file as above. Removing this extra backslash \ resolved my problem. So, check your orm.xml file after you use the command php app/console doctrine:generate:entity to make sure that there are no extra backslashes in the path. This bug may have been resolved in the later versions of Symfony, but just in case if you get this error, this could be the reason.


In my case it was a typo in Class name. I got an error in AssetsCommand.php when class name was named as AsssetsCommand

Make sure that class file's base name is identical to class name.


Felt like every answer I read would solve it but didn't. In my case it was ultimately OpCache. Forgot I had it turned on during development. Solution is to either restart the PHP-FPM or Httpd (when using mod_php) everytime the a change is made to the codebase or disable OpCache completely.


It happens to me when I declare wrong namespace. Example: Namespace AppBundle\Controller;

but the class is at this path: AppBundle\RestController


If this error popus up, you should check your file names for typos as well. In my case however it said "The file was found but the class was not in it, the class name or namespace probably has a typo", in fact the file name was not correct ("From" instead of "Form")


Need Your Help

"java.lang.RuntimeException: Could not launch intent" for UI with indeterminate ProgressBar

android android-intent android-progressbar android-espresso android-instrumentation

Are there any known issues with displaying indeterminate ProgressBars with the AndroidJUnitRunner?  I'm hitting this error during tests:

How do I optimize image auto-adjustment on window resize and init

javascript jquery html optimization resize

I have a page wich can contain up to 8 cards. The card are all 1:1 width/height sizes. The cards must be at least 250px wide and a maximum of 350 pixels wide. But the screen only has place for a co...