NotionCommotion Posted May 8, 2017 Share Posted May 8, 2017 I've written multiple generic methods which are not specific to any class or application. Examples include initiating a http request, recursive searching an array, displaying a pdo query for troubleshooting, etc. For some projects, I've tried to separate them in different classes based on what they do and have called them statically, and for other projects, I have just dumped them in a "Helper" class, and have had all other classes extend that class. What should I be doing? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 8, 2017 Share Posted May 8, 2017 If all of these disparate functions that you have written do not logically 'fit' together, then lumping them into a helper class unnecessarily bloats any script that you use it in. I have many many modules that I have written that I include when needed as separate functions without trying to 'class-ify' them. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted May 8, 2017 Author Share Posted May 8, 2017 How do you manage them? Maybe something like the following? I was also thinking there might be a good way to do so using composer. public function execFunction($function,array $arr) { if (!function_exists($function)) { require("/path/to/$function"); } return $function($arr); } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 8, 2017 Share Posted May 8, 2017 Again - more useless code. If you WANT a certain function available, you just include/require it. That's my philosophy. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 8, 2017 Share Posted May 8, 2017 separate them in different classes This. And an autoloader. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted May 8, 2017 Author Share Posted May 8, 2017 This. And an autoloader. Yes, I use an autoloader. Recommend calling them statically if they only perform a single set functionality? No good reason to attempt to use composer to manage? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 8, 2017 Share Posted May 8, 2017 (edited) Recommend calling them statically if they only perform a single set functionality? Yes. No good reason to attempt to use composer to manage? I don't see the point. Since you already have an autoloader and are in an OO environment, putting the features into (static) methods is the obvious solution. Why create a parallel infrastructure? Edited May 8, 2017 by Jacques1 1 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.