Efficiency for including files of functions (in PHP)(包含函数文件的效率(在 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.
这篇关于包含函数文件的效率(在 PHP 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含函数文件的效率(在 PHP 中)
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01