Customize functions

What's good: keep all functions in one file or separate them? (e.g. database.php, session.php)

+2


a source to share


2 answers


My approach breaks down the functionality into classes; and then put each class in one file.

If you have a lot of functions, I would do the same - split them into thematically separate files and include them only when needed.



If you are working with classes, you can use the PHP autoloader functionality , which will automatically load any PHP files needed to instantiate a specific class.

+2


a source


I prefer to use several different files - usually one group of "functions" each.

Benefits:



  • smaller files: easier to work with the IDE
  • several files: one developer can work with one function, in one file, another development for another function, in another file; limits the risks of conflicts (yes, even with SVN and equivalents)
  • you only need to include what you need


(And if you expand your question to classes: one class for each file, structured in directories and using autoloading to include the required files)

0


a source







All Articles