Symfony Database Code Error

I have Symfony 2 that has successfully installed and configured and was doing documentation through.

I am now up to http://symfony.com/doc/2.0/book/doctrine.html

Everything is fine until I get to this line:

php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Product 

at this moment i get the following error:

 [RuntimeException] The autoloader expected class "Acme\StoreBundle\Entity\Product" to be defined in file "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Symf ony\app/../src\Acme\StoreBundle\Entity\Product.php". The file was found but the class was not in it, the class name or namespace probably has a typo. 

This happened to me on both Linux and Windows machines.

The content of Product.php corresponds to the tutorial:

 // src/Acme/StoreBundle/Entity/Product.php namespace Acme\StoreBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="product") */ class Product { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=100) */ protected $name; /** * @ORM\Column(type="decimal", scale=2) */ protected $price; /** * @ORM\Column(type="text") */ protected $description; } 
+6
source share
2 answers

This message comes from DebugUniversalClassLoader.php:

 public function loadClass($class) { if ($file = $this->findFile($class)) { require $file; if (!class_exists($class, false) && !interface_exists($class, false)) { throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file)); } } } 

So, the file should be there and readable, otherwise findFile and require did not work. All this checking is done by require() on the file, and then using standard PHP class_exists () to find out if the class exists.

The only thing I can think about is that this message will receive these files: you missed the <?php at the beginning of the file. Now I know that this happens a little, but I honestly can’t think of anything else that will not cause any other error.

+25
source

I had the same error: "The file was found, but the class was not in it, the class or namespace probably has a typo." This is only because

 <?php 

missing at the beginning of the file! Argh, copy-paste from the tutorial ... Bye!

+1
source

Source: https://habr.com/ru/post/897665/


All Articles