包含函数文件的效率(在 PHP 中)
如果我有大量函数,最好将它们全部保存在一个大文件中,或者将它们分成几个相关函数的文件.更好是指在可维护性和处理请求的服务器方面更高效.
If I had a large number of functions would it be better to keep them all in one large file or would it be better to separate them into several files of related functions. By better I mean more efficient for both maintainability and for the server processing the request.
例如,现在我将所有文件都放在一个名为 include.php
的文件中.但是拥有一个包含如下内容的包含文件会更明智:
For example right now I have all my files in a file named include.php
. But would it be wiser to have an include file of includes like:
<?php
include('/functions/user.php');
include('/functions/admin.php');
include('/functions/content.php');
include('/functions/nav.php');
include('/functions/database.php');
include('/functions/other_junk.php');
?>
推荐答案
为了可维护性,一定要把它们分开.我怀疑性能是否会受到影响,但即使它会受到影响(只是一点点),你最好还是编写可维护、可读的代码.
Definitely separate them, for maintainability sake. I doubt performance will suffer at all, but even if it does (just a teensy bit) you're better off writing maintainable, readable code.
相关文章