symfony/symfony — Issue #2603: When inproperly configured MessageCatalogue::get() causes an infinite loop
Author: olegstepura
Created: 2011-11-10 14:07:02+00:00
State: open

Hi!

I was having this config:

```
framework:
...
default_locale: pt-br
...
translator:
enabled: true
fallback: pt-br
```
And catched an infine loop on the line `127` of the `\Symfony\Component\Translation\MessageCatalogue::get()`.

I'm not so well informed of the inside workflow of this component to propose a pull request but my suggestion is to create a check in this code:

```
if (null !== $this->fallbackCatalogue) {
return $this->fallbackCatalogue->get($id, $domain);
}
```

It should be replaced with

```
if (null !== $this->fallbackCatalogue) {
if ($this->fallbackCatalogue !== $this) {
return $this->fallbackCatalogue->get($id, $domain);
}
}
```

or maybe better

```
if (null !== $this->fallbackCatalogue) {
if ($this->fallbackCatalogue->getLocale() !== $this->getLocale()) {
return $this->fallbackCatalogue->get($id, $domain);
}
}
```

I'm not sure which one is better.

Also I think it would be nice to detect self-referencing here and throw an exception since it was a pain to find out what is happening in production when after an infinite loop PHP was causing a fatal error and silently closed without error handler being able to catch an error.