Description
Transparent extension via the cascading filesystem has become the bane of Kohana's existence. On the surface transparent extension seems like a great idea, that is until you dig a little deeper and realise all of its imperfections. Transparent extension hinders the development of Kohana in that it forces non-modern, annoying, and strange conventions.
Here are some flaws of transparent extension (you may know of more):
- Forces us to create an empty child class for all classes - normally in the format of
Kohana_Foo -> Foo
. Without an empty child class users can't extend specific methods, they would have to duplicate the whole class. It becomes even messier when a module extends something from the core as it has to create another parent and child class:Module_Foo -> Foo
. - When referencing a class's own property or method you're forced to use the explicit class name
Foo::$bar
instead ofself::$bar
. The reason is explained nicely here by @evanpurkhiser. - Two different modules can't extend the same class as one of them will be ignored.
- IDEs don't know when classes have been extended via the cascading filesystem and as a result cannot provide correct information to you when developing.
I believe that transparent extension was built at a time when PHP wasn't so good at it. Let's rid ourselves of this outdated, hacky implementation and get back to writing clean PHP using the proper method of extension. Deprecating it now would give users (and us developers) ample warning to start eradicating the use of transparent extension before the next major release.
Replacement
Instead of using the CFS autoloaders it would be recommended to register modules with the composer PSR-0 autoloader. Over the period of the next minor releases leading up the to the major, inversion of control should be applied to all existing classes. Users will then be able to inject their own or extended implementations instead of using transparent extension. Dependency injection (if applied to all classes) would offer the same extensive ability as the CFS provided.
Targeted Version
Deprecation: 0.1 (Kohana 3.4)
Removal: 1.0 (Kohana 4.0)
Implementation
Deprecating transparent extension is as simple as adding @deprecated
tags to the doc blocks of the autoloader classes, abstract class, and interface located in this package.