ginzmoney Posted February 18, 2013 Share Posted February 18, 2013 I currently maintain a large PHP (5.4) codebase w/ 500+ classes. We provide a custom client/application override structure that allows classes to be dynamically extended when necessary. All classes exist in the root lib/ directory, with sub-directories for each custom client (i.e. lib/foo/). By utilizing __autoload() we instantiate the appropriate class at run time and class_alias it to the requested name (i.e. class bar extends bar_base) I'd like to further organize the classes into appropriate sub-directories, but can't figure out a way to achieve that without namespacing. I don't want to sequentially scan all sub-dirs when instantiating an object, but can't think of a solid way to key the autoloader off to where the class exists. The one idea I've been playing with is naming the classes with leading underscores (_profiile_registration), but it seems hacky. Any insight at all is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/274626-class-sub-directories-without-namespacing/ Share on other sites More sharing options...
Christian F. Posted February 18, 2013 Share Posted February 18, 2013 If the files are sorted on a per-client basis, you might be able to do away with a lot of the naming with using constants. That said, however, you really should be considering using namespaces here. This is exactly the thing they were added for, after all. Quote Link to comment https://forums.phpfreaks.com/topic/274626-class-sub-directories-without-namespacing/#findComment-1413109 Share on other sites More sharing options...
ginzmoney Posted February 18, 2013 Author Share Posted February 18, 2013 I'm not a big fan of PHP Namespaces yet. It's still lacking some functionality that would make the conversion effort worthwhile for me. If there was a way to import the global namespace that would probably be worthwhile. Quote Link to comment https://forums.phpfreaks.com/topic/274626-class-sub-directories-without-namespacing/#findComment-1413110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.