symfony/http-kernel · error · LogicException
Users will expect the alias of the default extension of a…
Error message
Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias. What it means
Symfony's Bundle::getContainerExtension() auto-discovers a bundle's DependencyInjection extension and enforces the naming convention: the extension alias must be the underscored version of the bundle name with the "Bundle" suffix stripped (e.g. AcmeFooBundle -> acme_foo). A LogicException is thrown when the extension class exists but its getAlias() returns something else, because container parameter/keys would confuse users.
Solutions
- Rename the extension's getAlias() return value to Container::underscore(basename-without-Bundle-suffix), e.g. return 'acme_foo';
- Alternatively rename the Extension class so the conventional getAlias() computes the correct alias automatically.
- If a non-conventional alias is truly intended, override Bundle::getContainerExtension() explicitly (as the message says) so the convention check is bypassed.
Example fix
// before
class AcmeFooExtension extends Extension
{
public function getAlias(): string
{
return 'foo';
}
}
// after
class AcmeFooExtension extends Extension
{
public function getAlias(): string
{
return 'acme_foo';
}
} Defensive patterns
Strategy: validation
Validate before calling
$expected = \Symfony\Component\DependencyInjection\Container::underscore(preg_replace('/Bundle$/', '', $bundle->getName()));
if ($extension->getAlias() !== $expected) {
// fix alias before registering
} Try / catch
try { $ext = $bundle->getContainerExtension(); } catch (\LogicException $e) { /* fix extension alias in DI extension class */ } Prevention
- Never override getAlias() unless you also override getContainerExtension()
- Follow the <Vendor><Name>Extension naming convention matching the bundle name
- Test bundle registration in a smoke test so alias mismatches surface in CI
When it happens
Trigger: Registering a bundle whose Extension class (e.g. AcmeFooBundle\DependencyInjection\AcmeFooExtension) returns an alias from getAlias() that does not equal Container::underscore('AcmeFoo'); typically when getAlias() is overridden to return a custom string, or the extension class name deviates from the convention so the parent getAlias() fallback derives a wrong alias.
Common situations: Renaming a bundle without renaming its Extension class or alias; hand-writing getAlias() to a shorter/prettier name like 'foo' while the bundle is 'AcmeFooBundle'; copying an extension from another bundle and forgetting to update getAlias().
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Controller " " has required constructor arguments and does…
- Controller " " cannot be fetched from the container because…
- Request payload contains invalid "form" data.
- Unsupported format: " ".
- Request payload contains invalid
AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13).
Data as JSON: /api/errors/b183773fd13260a2.
Report an issue: GitHub.
Appendix: source
Thrown at Bundle/Bundle.php:48
*
* @throws \LogicException
*/
public function getContainerExtension(): ?ExtensionInterface
{
if (!isset($this->extension)) {
$extension = $this->createContainerExtension();
if (null !== $extension) {
if (!$extension instanceof ExtensionInterface) {
throw new \LogicException(\sprintf('Extension "%s" must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.', get_debug_type($extension)));
}
// check naming convention
$basename = preg_replace('/Bundle$/', '', $this->getName());
$expectedAlias = Container::underscore($basename);
if ($expectedAlias != $extension->getAlias()) {
throw new \LogicException(\sprintf('Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias()));
}
$this->extension = $extension;
} else {
$this->extension = false;
}
}
return $this->extension ?: null;
}
public function getNamespace(): string
{
return $this->namespace ??= false === ($pos = strrpos(static::class, '\\')) ? '' : substr(static::class, 0, $pos);
}
public function getPath(): string
{View on GitHub (pinned to aa3a39d728)