开发者

Set apart functions [closed]

开发者 https://www.devze.com 2022-12-28 07:33 出处:网络
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
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

精彩评论

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

关注公众号