zendframework/zf2 — pull request #4790 by nickpeirson (2013-07-05 14:25:17+00:00)
Title: Add check to DI to see if we have a class to instantiate

Currently the DI container throws a fatal error when trying to instantiate a class that doesn't exist or, more usually, when DI tries to instantiate an interface.

The fatal error looks like:

PHP Fatal error: Cannot instantiate interface Foo\Bar in /Users/nickpeirson/projects/mycg/vendor/zendframework/zend-di/Zend/Di/Di.php on line 452

This PR changes the behaviour to check for the existence of the of the class before trying to instantiate it and throws and exception accordingly. This results in a much more developer friendly backtrace allowing a developer to identify the problem more quickly and spend less time debugging. As we see this most commonly when we've missed a type preference for an interface I've also added a case for when the class to be instantiated is in fact an interface, to add clarity to the thrown exception.