8000 [RFC] Normalize root namespaces with DI · Issue #28006 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[RFC] Normalize root namespaces with DI #28006
Closed
@ro0NL

Description

@ro0NL

Description
For context see: symfony/symfony-docs#8403 and #24145

Nobody should prefix their service name by a \ IMHO.
-- nicolas-grekas

Currently only namespaced classes are detected as "class named services", i.e.

MyClass: ~ # doesnt work
\MyClass: ~ # doesnt work
\My\Class: ~ # doesnt work
My\Class: ~ # works

I propose to deprecate leading slashes in service ids. So you most likely end up with the working/last example in the future.

In case a class lives in the root namespace (first example) you'd get the error about a missing class attribute which we can easily explain: "root class named services" are not supported. Hence you must specify the class attribute. Which brings me to the next point;

Currently it's allowed to use both class: MyClass and class: \MyClass which causes some form of inconsistency, and makes $def->getClass() === MyClass::class error prone.

I propose to normalize leading slashes in a service its class attribute. Although i tend to prefer a deprecation here as well.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0