tags:

views:

28

answers:

2

What is good way: Keep all functions in one file or to set apart them? (like database.php, session.php) Thanks in advance

A: 

I prefer using several distinct files -- generally, one per "group of features".

Advantages :

  • smaller files : easier to deal with in your IDE
  • several files : one developper can work on one feature, in one file, the other developper on another feature, in another file ; limits the risks of conflicts (yes, even with SVN and equivalents)
  • you only need to include what's needed


(And if you extend your question to classes : one class per file, structured in directories ; and using autoloading to include the files that are necessary)

Pascal MARTIN
+2  A: 

My approach is split functionalities into classes; and then to put each class into 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 work with classes, you can make use of PHP's autoloader functionality that will automatically load any PHP files needed to instantiate a certain class.

Pekka
+1 for classes and autoload
knittl