Hi guys || girls,
I'm posting here to get a bit of feedback on an idea I have to bring organisation to the way in which we rename a class for auto-loading while having to support the original class name for backwards compatibility.
This proposal uses the existing auto-loading code and cache to intercept requests for a deprecated class that has been renamed. When a request is intercepted the autoloader creates a class alias for the old name to the new name and issues a developer debug call to advise the upgrade of code to use the new name.
Things worth knowing about this proposal:
- Extends the existing auto-loading system and cache.
- Renamed classes get registered in a new db/renamedclasses.php file.
- The old class can be removed entirely, leaving just the registration above.
- The debugging notice only gets issued once per class. So even if the old class name is used frequently in your code you will only get a single debugging call.
- By using class_alias the two classes appear identical and things such as type-hinting on the old and new names both continue to work.
In my mind the big advantage to this approach is that we can truly benefit from auto-loading with this method as essentially it is allowing both the new and old classes to be auto-loaded rather than the current approach of making the old class extend the new class which because the old class had to be included manually means we don't actually auto-load the new class. This makes renaming impractical at present. One other advantage is that debugging notice. With this we would have a standard message displayed reliably for all renamed classes.
To see the complete picture in code check out the diff on github.
As proof of concept and as part of the patch I have converted the textlib, collatorlib, plugin_manager, and plugininfo_base deprecated classes. I also imagine this will be used with the upcoming output changes.
Please if you've an opinion or thoughts on this share them either here or on the issue, and feedback is most welcome.
Many thanks Sam