purpleshadez Posted October 25, 2009 Share Posted October 25, 2009 I have been thinking about a method of simulating the __autoload() function that will work in PHP4. Currently I'm using something like this: foreach(glob($path . '*.php') as $class_name) { if( ! preg_match("/index.php/i", $class_name)) { require_once($class_name); } } As expected this will included all files with with .php extension excluding index.php from the specified file path. Now with a small set of classes I can't really see this as a problem especially if almost all of them are core classes required for the application to work. However, in time I imagine there will be more and more classes that will not be used on a regular basis such as excel exports or generating word documents that really do not need to be loaded on each and every page. Would it be better to perhaps use the above method with a folder path that only contains the core classes and then keep the others in a seperate location and manually include them when needed or is there another way to only load those that are needed? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 25, 2009 Share Posted October 25, 2009 That's hardly a simulation of autoloading. It just loads all files in given location, while autoloading tries to load classes on demand. Why are you even doing anything in PHP4? Quote Link to comment Share on other sites More sharing options...
purpleshadez Posted October 25, 2009 Author Share Posted October 25, 2009 That's hardly a simulation of autoloading. It just loads all files in given location, while autoloading tries to load classes on demand. Why are you even doing anything in PHP4? I am aware it doesn't do what autoload does, I was after a better method that would work in a more efficient way than the example I provided. As for why, a number of business processes prevent me from being able to upgrade to the latest version. Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 25, 2009 Share Posted October 25, 2009 I doubt you can do anything more in PHP4 except perhaps what you mentioned in your first post. Either storing different class 'families' in different folders, or including 'family name' in their filename (like 'excel.reports.php') And then calling function like autoload('excel'); //loads all excel classes Quote Link to comment Share on other sites More sharing options...
purpleshadez Posted October 25, 2009 Author Share Posted October 25, 2009 I doubt you can do anything more in PHP4 except perhaps what you mentioned in your first post. Either storing different class 'families' in different folders, or including 'family name' in their filename (like 'excel.reports.php') And then calling function like autoload('excel'); //loads all excel classes I like the family name idea, just prefix the class & filenames and call them when needed. Not perfect, but better than my current solution. I could beat the sys admin to death with his keyboard then do the update myself.... Cheers Mchl I think I'll go with that. Quote Link to comment 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.