From fedc522fa2599963b97aa05b059fd45b0f1c2670 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 28 Jan 2018 11:11:12 +0100 Subject: [PATCH] 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. --- service_container/alias_private.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index ff0af7aa2e0..427ec92f9a6 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -57,12 +57,11 @@ What makes private services special is that, if they are only injected once, they are converted from services to inlined instantiations (e.g. ``new PrivateThing()``). This increases the container's performance. -Now that the service is private, you *should not* fetch the service directly +Now that the service is private, you *must not* fetch the service directly from the container:: $container->get('foo'); -This *may or may not work*, depending on if the service could be inlined. Simply said: A service can be marked as private if you do not want to access it directly from your code.