PHP加载目录中的每个类
我编写了一个PHP脚本,其中包含目录中的每个文件。但是我想知道是否有一种方法可以加载我包含的文件中的类,比如自动加载器之类的PHP加载目录中的每个类,php,Php,我编写了一个PHP脚本,其中包含目录中的每个文件。但是我想知道是否有一种方法可以加载我包含的文件中的类,比如自动加载器之类的 <?php define("include_dir", dirname(__FILE__) . '/includes/'); foreach (scandir(include_dir) as $filename) { if (is_file(include_dir . '/' . $filename)) { //its a ph
<?php
define("include_dir", dirname(__FILE__) . '/includes/');
foreach (scandir(include_dir) as $filename)
{
if (is_file(include_dir . '/' . $filename))
{
//its a php file, lets do this!
if (substr($filename, -4) == '.php')
{
include include_dir . $filename;
}
}
}
?>
试试这个-
function __autoload($class_name) {
include $class_name . '.php';
}
$obj = new MyClass1();
$obj2 = new MyClass2();
手册-
http://php.net/manual/en/language.oop5.autoload.php
当然你在谷歌上搜索过PHP Autoloader吗,还是你自己编的?如果是第一个,你发现了什么?如果是第二种情况,尝试谷歌搜索,你会发现:你说我的负载是什么意思?简单包含文件应使availableperhaps中的任何类在每个文件中创建一个扩展类,并将其命名为LoadPlugin或类似名称,然后在包含循环结束时执行LoadPlugin?如何访问该类?比如$class->function如果你必须自己定义一个新类,那么自动加载器有什么不同呢?它只包括你的文件?