PHP中每个文件只有一个或多个函数? [英] Only one or many functions per file in PHP?

查看:117
本文介绍了PHP中每个文件只有一个或多个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,当我在php中设计我的应用程序时,真的让我感到困惑:我不知道是否应该为每个函数创建分离文件(例如:用于验证特定表单的函数)。

好的,有人可能会认为这没有意义,因为我必须将每个文件分开包含,这会导致应用程序更慢。

但是我仍然认为它确实有道理,因为对于一个页面载入我怀疑其他函数是否会被脚本使用,所以它们必须被加载只是为了什么?除此之外,如果我设计的系统为我做了这个dinamically(解析url变量或类似的),也就是说,在需要时加载函数(-files),我不必手动包含每个函数文件。你认为什么?

解决方案

文件包含的开销很小,你不必担心它,考虑到缓存和其他东西。它更多的是关于如何保持自己的组织和快速找到你的东西。

老实说,我很少使用函数,我使用类。该规则通常是每个文件都有一个类。但我也有一个包含我所有全局函数的 toolbox 文件。


I have this problem that is really causing me headeches whenever i'm designing my apps in php: I don't know if i should create separete files for each function(e.g.: functions for validating specific forms).

OK, one would possibily argue that this makes no sense because I would have to include each file separetly and this would result in a more slow application maybe?

But I still think it does make sense since for one pageload i doubt that other functions would be used by the script at all, so they must be loaded just for nothing? besides, i don't have to include each function-file manually if the system i design does this dinamically (parsing url vars or such) for me, that is, loading function(-files) exactly when needed. What do you think?

解决方案

The overhead in file includes is minimal, you shouldn't have to worry about it really, considering caching and other things. Of It's more about how you can keep yourself organized and find your stuff quickly.

Honestly, I rarely use functions, I use classes. The rule is usually to have a class per file. But I also have a toolbox file that contains all my global functions.

这篇关于PHP中每个文件只有一个或多个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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