-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The container screencast should not say that you can use anything as id #5
Comments
@stof WOW. I actually didn't know about the optimizations - that's really sweet :). I've added a note at sha: 897b006 and @Leannapelham is encoding that note into the video. Thanks - I try to be a bit more casual in the screencasts, but not with the intention to be incorrect :). |
@weaverryan the fact that ids are case insensitive is not an optimization. It should be explained explicitly IMO (it is a big difference with array keys) |
@stof So the key points are that: A) Some characters are not valid (I think I've covered that with the note - i.e. stick to the standard, or else risk hitting some invalid chars) Does that sum it up? If so, I'll get a note that suits this - I want it to be as short as possible, but this is a more advanced tutorial, so it fits. Thanks! |
yes, this is OK. |
Thanks - I've updated the note once more - hopefully it's good now :) |
Ids are always lowercase in the container. So if you try to set
logger
and thenLOGGER
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.
The text was updated successfully, but these errors were encountered: