一个类的“压缩”文件与PHP中的多个类文件 [英] One 'compressed' file of classes vs multiple class files in PHP
问题描述
将项目的所有类组合到一个庞大的压缩文件(已删除空格和注释)与按需加载每个类(不是所有类都存在,所以您没有)有什么好处?不必要求/包括它们,这不是我们拥有__autoload的目的吗?)?
在我看来,根据需要加载每个类会少很多
通常,在绝大多数情况下,对于任何非平凡的类,您都需要一些一种依赖注入。
(通过任何方法)依赖注入的开销将与解析一堆不会在特定请求中使用的类所需的资源相形见.。
关于如何根据需要有效地管理加载类的主题,已有很多论述。
Is there any gain to combining all of the classes for a project into one massive 'compressed' file (spaces and comments removed) vs loading each class as they are required (other than all of the classes are there so you don't have to require/include them, isn't that what we have __autoload for?)?
It seems to me that loading each class as needed would be a lot less strenuous on php.
Generally, in the vast majority of cases, for any non-trivial number of classes, you want some kind of dependency injection. The overhead of the dependency injection (via whatever method) will be dwarfed by the resources needed to parse a bunch of classes that won't get used in a particular request.
A lot has been written on the subject of how to efficiently manage loading classes as needed.
这篇关于一个类的“压缩”文件与PHP中的多个类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!