Php 已经包括在课堂上了

Php 已经包括在课堂上了,php,class,Php,Class,是否可以将我的类文件包含在文件夹的所有文件中?查看: (官方文件) 示例: function __autoload($class_name) { require_once $class_name . '.php'; } $obj = new MyClass1(); $obj2 = new MyClass2(); 尝试使用类自动加载: 非常有用您还可以使用-set php.ini、httpd.conf或.htaccess文件中的路径自动为文件添加前缀: Specifies the

是否可以将我的类文件包含在文件夹的所有文件中?

查看:

(官方文件)

示例:

function __autoload($class_name) {
    require_once $class_name . '.php';
}

$obj  = new MyClass1();
$obj2 = new MyClass2(); 

尝试使用类自动加载:


非常有用

您还可以使用-set php.ini、httpd.conf或.htaccess文件中的路径自动为文件添加前缀:

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.

还有
auto\u prepend\u文件
configuration选项
因此,您可以使用以下行将.htaccess文件(如果您以Apache模块的形式运行PHP)添加到该文件夹中:

php_value auto_prepend_file /path/to/that/file

除了使用前面提到的,您还可以在加载之前在.htaccess文件中指定一个具有的文件:

php_value auto_prepend_file foo.php
这样,只要请求该目录或子目录中的php文件,就会加载foo.php文件