First let me say that I'm not against PSR-0, I think it is the right way to accomplish interoperability between different projects. But I'm against including the class in the proposed form into the PHP core. Not because of all the things said by other developers, for me its more a design decision.
Design decision?In my opinion the class violates against one of the fundamental OOP principles. The principle what I mean is the Single responsibility principle introduced by Robert C. Martin. This principle says that a class should only have one responsibility, and that responsibility should be entirely encapsulated by the class. But the class provided by the patch shares two responsibilities. The first is to load classes which follows the PSR-0 draft and the second is to load classes automatically. So following this principle the class SPLClassLoader should only load classes. The autoloading part should be implemented in an additional class.
Another important thing is that the PSR-0 draft says not how classes should be loaded. The draft only describes how classes should be named so that they can be loaded across different projects. The proposed patch is only one possible variant to load classes which follows the PSR-0 draft. There exists some other variants:
- Classes can be loaded from PHP include path
- Classes can be loaded from a static map
- Class paths can be cached
Any suggestions?Yes. A suggested above, one possible solution would be to split the concerns into separate parts. The first part should be an interface
ClassLoader: The second part should be an
ClassAutoloaderclass itself: Note that this is only one possible solution of an autoloader class.
What are the benefits?Now that we have split the proposed class in their concerns, it would be possible to implement all conceivable
ClassLoaderimplementations in userland or fair enough in core. The
ClassAutoloaderclass provides an simple interface for registering the preferred
ClassLoaderimplementation, regardless of whether if it's PSR-0 or not.
Now, what is your position?I'm not sure if PHP should implement all possible
ClassLoadersolutions(including the PSR-0 variants). Because they can all be implemented in userland and I think the performance boost, if implementing it in core, is marginal.
But I think all developers out there would be benefit from an object oriented interface to register
ClassLoaderimplementations for autoloading. So it's easy to share class loaders across other projects because of the consistent interface. This is more interoperability as including a single class loader implementation in core.