Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php在多个文件夹上自动加载多个文件?_Php_Autoload - Fatal编程技术网

使用php在多个文件夹上自动加载多个文件?

使用php在多个文件夹上自动加载多个文件?,php,autoload,Php,Autoload,如何自动加载可能存储在多个文件夹中的多个文件? 我已经做的就像在图片上展示的: 在Index.php[init.php]创建所需的文件,该文件包含: <?php spl_autoload_register(function ($class){ require_once "classes/class.$class.php"; }); 当@dan miller注释提到检查文件是否存在时,问题得到了解决,然后每个新文件夹都需要检查文件 <?php spl_autoload_re

如何自动加载可能存储在多个文件夹中的多个文件? 我已经做的就像在图片上展示的:

在Index.php[init.php]创建所需的文件,该文件包含:

<?php
spl_autoload_register(function ($class){
    require_once "classes/class.$class.php";
});

当@dan miller注释提到检查文件是否存在时,问题得到了解决,然后每个新文件夹都需要检查文件

<?php
spl_autoload_register(function ($class){
    $filename="classes/$class.php";
        if(!file_exists($filename))
        {
            return "file : $filename is not Exist on the Given Path";
        }
    require_once "classes/$class.php";
});
spl_autoload_register(function ($class){
    $filename="conf/$class.php";
        if(!file_exists($filename))
        {
            return "file : $filename is not Exist on the Given Path";
        }
    require_once "conf/$class.php";
});

使用PSR-4自动加载程序(它随composer一起提供)@tereško你能举个例子吗?你可以使用
spl_autoload_register注册另一个自动加载函数
你说得对,那实际上是行不通的。它应该检查文件是否存在。也许可以检查这个问题: