Hey people, This might sound as a surprise, but thanks to Nicolas' and Matthew's comments, I came up with yet another solution that was never really discussed.
PR (WIP) is here: https://github.com/php-fig/fig-standards/pull/869 Nicolas and Matthew pointed a few things that were never said before. Namely: - The NotFoundExceptionInterface duplicates the concept of the has method (in Nicolas post) - Using exceptions for control flow is often a questionable design choice (in Matthew post) Based on these 2 assertions (I agree with both), we should question the usefulness of NotFoundExceptionInterface as it is defined today. We spent a lot of time to make sure that containers implementing PSR-11 are differentiating the NotFoundExceptionInterface from a "missing dependency exception" (that should exist in the container even if it is not standardized). This involves that implementing containers MUST catch the NotFoundExceptionInterface and rethrow another exception. So we are forcing an "implementation detail" into implementors. And I've come to realize that contrary to what I believed, we absolutely don't need that. The change I'm proposing is dead simple: let's drop any distinction between "entry not found" and "dependency missing". We don't need this because users of containers can anyway figure that out. If a user of a container wants to make the distinction between "not found" and "missing dependency", he can simply perform a call to has before calling get: if (!$container->has($id)) { // The requested instance does not exist // Let's do some stuff like display an error message return;}try { $entry = $container->get($id);} catch (NotFoundExceptionInterface $e) { // Since the requested entry DOES exist, a NotFoundExceptionInterface means that a dependency is missing!} Advantages: - it is dead simple - we don't dictate that NotFoundExceptionInterface must not bubble up (no forced catch and rethrow, which feeled a bit flacky) - containers can do whatever they want: - either let NotFoundExceptionInterface bubble up - or catch the NotFoundExceptionInterface and wrap it in a "MissingDependencyException" of their own that must itself implement the NotFoundExceptionInterface Inconvenient: - slight incompatibility with container-interop, since in container-interop, the "MissingDependencyException" was not supposed to implement the NotFoundExceptionInterface (this is actually not clearly stated in the container-interop documentation) The more I think about it, the more I'm seduced by this solution. It is simple, it leaves complete freedom to implementors, and container users can still figure out if the exception they get is a "not found" or a "missing dependency" with a simple has call. It also enforces best practices as users that want to check if an entry exists will use has instead of NotFoundExceptionInterface (the exception can no more be used for control flow) Note: I haven't had a chance to speak with Matthieu, the other editor, about it yet since deadlines are tight, I'm sharing it right now. Matthieu, if you think this is foolish, we can cancel that. As you can see, the PR makes PSR-11 even more simple, which is generally a good sign: https://github.com/php-fig/fig-standards/pull/869 What do you guys think? ++ David. -- You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscr...@googlegroups.com. To post to this group, send email to php-fig@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/228fa8aa-1046-4598-a3dc-e8c3a4ca2037%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.