Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.