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

查看:108
本文介绍了包含函数文件的效率(在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天全站免登陆