I’ve a serious problem with a Symfony 2.0.16 installation. Cache file generated for a simple service is wrong.
One service replacer.factory, sort of factory one. I’ll show only a simplified version:
/**
* @DI\Service("replacer.factory")
*/
class ReplacerFactory
{
/**
* @DI\InjectParams({"container" = @DI\Inject("service_container")})
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getReplacer($object)
{
$replacer = new NewsletterReplacer($this->container);
// Return the instance of NewsletterReplacer class
return $replacer->setInstance($object);
}
}
And this is the instance returned, again a bit simplified:
class NewsletterReplacer
{
private $container;
private $instance;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function setInstance(Newsletter $newsletter)
{
$this->instance = $newsletter;
}
}
For some reason, cache file generated is completely wrong.
In fact, this is part of appDevProjectContainer.php file, after the command php app/console cache:clear --env=dev --no-debug:
protected function getReplacer_FactoryService()
{
return $this->services['replacer.factory']
= new \Acme\HelloBundle\Service\Replacer\NewsletterReplacer();
}
It should be instead:
protected function getReplacer_FactoryService()
{
return $this->services['replacer.factory']
= new \Acme\HelloBundle\Service\Replacer\ReplacerFactory($this);
}
So, what’s wrong and how can i solve it?
It was a PHP bug with annotation along with JMSDiExtraBundle, see this issue. Solved updating PHP 5.3.3-7.