Description
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?