开发者

Set apart functions [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 8 years ago.

开发者_JAVA技巧 Improve this question

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


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜