我对在 PHP 中加载依赖类的正确方法/最佳实践有疑问。
include_once
我通常以类似于 Java 导入的方式将所有依赖项放在每个类的开头。就像是:
include_once 'dto/SomeObjectDTO.php;'
include_once 'dao/SomeObjectDAO.php;'
include_once 'util/SomeObjectUtil.php;'
class SomeObjectService{
#class code here
}
这是加载类的最佳方式吗?或者也许将所有类加载到Bootstrap.php
? 其他方法?
请注意,我说的是加载我自己的类,而不是像框架这样的复杂外部类。