Question

Is it possible to run require_once recursively in one line like this:

<?php
require_once('./OAuth2/*');

Or would you have to go to each file directly and require it?

Was it helpful?

Solution

cant do it that way. something like this would work:

foreach (glob("./OAuth2/*.php") as $filename)
{
    require_once($filename);
}

OTHER TIPS

recursively all file list and require_once in one directory:

$files = array();

function require_once_dir($dir){

       global $files;

       $item = glob($dir);

       foreach ($item as $filename) {

             if(is_dir($filename)) {

                  require_once_dir($filename.'/'. "*");

             }elseif(is_file($filename)){

                  $files[] = $filename;
             }
        }
}

$recursive_path = "path/to/dir";

require_once_dir($recursive_path. "/*");

for($f = 0; $f < count($files); $f++){

     $file = $files[$f];

     require_once($file);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top