Autoloader expected Symfony2 class

I use the symfony 2.3 structure, and the autoloader claims to have found the file, but not the 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 referenced file is shown below:

 <?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(); } } 

In any case, some of the details that may help is that I recently installed Doctrine and executed the commands ...

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

After these commands, Symfony stopped working. I don’t know if this is some kind of strange mistake or something like that. If you need more information, I can publish it. Thanks for any help.

+7
source share
11 answers

A missing (or short) PHP open tag can also cause this error. Yes, that sounds funny, but if you just follow the Symfony example and copy / paste the whole class, you may not notice it (as I did not).

+17
source

Now this is a bit old-fashioned, but if someone else gets here by searching: This is undoubtedly a cache problem. Manually delete the contents of app / cache / dev and app / cache / prod and everything should be allowed.

+5
source

If someone else has this problem and it doesn’t disappear, clearing the cache, I recommend deleting the entire folder with your composer dependencies and running composer install again.

It worked for me :).

+2
source

I think there is a bug in Symfony2. They recently upgraded to the new version (2.3.1) of symfony, which, I think, should break something. Anyway, I had to comment // the new line Sensio \ Bundle \ FrameworkExtraBundle \ SensioFrameworkExtraBundle () in the AppKernel.php file to get rid of this error.

0
source

Make sure your namespace is defined in the class you are trying to use. For example, in my controller, I had:

 use Acme\DemoBundle\Amazon\AmazonProductAPI; 

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

 namespace Acme\DemoBundle\Amazon; 
0
source

@MilanG's answer helped me! I switched my PHP configuration from

 short_open_tag = Off 

to

 short_open_tag = On 
0
source

I solved this problem by removing the 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 object, as well as the orm.xml file. This utility has an error, and it adds an additional \ to the xml file, as described above. Removing this extra backslash \ resolved my issue. So, check your orm.xml file after using the php app/console doctrine:generate:entity command to make sure there are no additional backslashes in the path. This error may have been resolved in later versions of Symfony, but just in case you get this error it might be the reason.

0
source

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

Verify that the base class file name is identical to the class name.

0
source

I felt that every answer that I read would solve it, but did not. In my case, it was ultimately OpCache. I forgot, I turned it on during development. The solution is to either restart PHP-FPM or Httpd (when using mod_php) every time you make changes to the codebase or completely disable OpCache.

0
source

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

but the class is on this path: AppBundle \ RestController

0
source

If this error occurs, you should also check your file names for typos. In my case, however, he said: “The file was found, but the class was not in it, the class name or namespace probably has a typo,” the file name was actually incorrect (“From” instead of “Form”)

0
source

All Articles