简体   繁体   English

PHP试图包含glob()目录的数组,但未找到最后一个

[英]PHP trying to include array of glob()'d directories and is not finding last one

Hello I have the following method: 您好,我有以下方法:

private static function loadIncludes()
{
    // prepare array of files from folders
    $files = array(
        glob(self::libPath()."/*.php"),
        glob(self::controllersPath()."/*.php"),
        glob(self::extensionsPath()."/*.php"),
    );

    // include files
    foreach ($files as $set)
    {
        if (is_array($set)) foreach ($set as $file)
        {
            require_once($file);
        }
    }
}

If I print_r the $files array it contains all the files but for some reason its not doing a require_once() on the last array item (/home/ * /app/extensions/Controller.php) see output: 如果我print_r $ files数组,它包含所有文件,但是由于某种原因,它没有对最后一个数组项(/ home / * /app/extensions/Controller.php)执行require_once(),请参见输出:

Array
(
    [0] => Array
        (
            [0] => /home/***/app/lib/CApp.php
            [1] => /home/***/app/lib/CController.php
            [2] => /home/***/app/lib/CDb.php
            [3] => /home/***/app/lib/CView.php
        )

    [1] => Array
(
            [0] => /home/***/app/controllers/SiteController.php
        )

    [2] => Array
(
            [0] => /home/***/app/extensions/Controller.php
        )

)

As the print_r shows even when there is only a single result it still an array, 如print_r所示,即使只有一个结果,它仍然是一个数组,

I believe the if (is_array($set)) can be left out. 我相信if(is_array($ set))可以省去。

As for why only the last one doesn't work i cannot say, 至于为什么只有最后一个不起作用,我不能说,

try debugging better by echoing every step of all for each loops 通过回显每个循环的所有步骤来尝试更好地调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM