How to include all files within a folder to functions.php?

You can include/require all *.php files recursively using following function.

foreach(glob(get_template_directory() . "/*.php") as $file){
    require $file;
}

Alternatively You can use following function as-well.

$Directory = new RecursiveDirectoryIterator(get_template_directory().'functions/');
$Iterator = new RecursiveIteratorIterator($Directory);
$Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);

foreach($Regex as $yourfiles) {
    include $yourfiles->getPathname();
}

P.S Got the solution From Here.

error code: 523