Jump to content

Class Sub-Directories Without Namespacing


ginzmoney

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.