包含函数文件的效率(在 PHP 中) [英] Efficiency for including files of functions (in PHP)

查看:24
本文介绍了包含函数文件的效率(在 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 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆