Skip to content

Commit fedc522

Browse files
committed
do never fetch private services from the container
Explaining that private services can still be fetched from the container under certain circumstances does not look like a good idea. Not only is it hard to grasp for beginners to understand why this sometimes works. It also becomes a real problem when upgrading to Symfony 4 where all private services won't be retrievable from the container through service location.
1 parent 136dadf commit fedc522

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

service_container/alias_private.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ What makes private services special is that, if they are only injected once,
5757
they are converted from services to inlined instantiations (e.g. ``new PrivateThing()``).
5858
This increases the container's performance.
5959

60-
Now that the service is private, you *should not* fetch the service directly
60+
Now that the service is private, you *must not* fetch the service directly
6161
from the container::
6262

6363
$container->get('foo');
6464

65-
This *may or may not work*, depending on if the service could be inlined.
6665
Simply said: A service can be marked as private if you do not want to access
6766
it directly from your code.
6867

0 commit comments

Comments
 (0)