Skip to content

The container screencast should not say that you can use anything as id #5

@stof

Description

@stof

Ids are always lowercase in the container. So if you try to set logger and then LOGGER later, it will actually overwrite the previous service.
Thus, Symfony optimizes the code path to retrieve services with their lowercase id (some improvements have been made, and others are still pending in PRs at this time). so using a non-lowercase id when calling get() will give you a performance penalty (which is not negligeable in case you retrieve lots of services. Ask the Drupal guys who asked for and contributed some of these optimizations)

Thus, using special chars will create issues once you start defining definitions and dumping the compiled container to PHP. The only valid characters when dumping containers are chars allowed in PHP identifiers (letters, digits and some unicode chars), underscores, dots and backslashes (with some conflicts in case you have 2 service ids differing only by a backslash vs a dot in the same place btw, or by an underscore vs no char).
This is why the Symfony best practices are to use dot-separated snake case parts when builing the id.

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