0

I have a few PHP files filled with multiple functions. Let's call them functions1.php, functions2.php, functions3.php:

function function_something( $atts ) {
     extract( something_atts( array(
        'foo' => 'bar',
        'bar' => 'foo,
        ), $atts ) );  

         return 'something'; 
}   

I'm loading these files within all_functions.php like this:

require_once('functions1.php');
require_once('functions2.php');
require_once('functions3.php');

I'm wondering if it's possible to create an array of all these functions and their attributes?

I'm thinking about something like:

function my_functions() {
    require_once('functions1.php');
    require_once('functions2.php');
    require_once('functions3.php');
}

And then some foreach loop, but I'm not sure how should it look like after all.

I know this probably looks tricky, but I'm just curious if I'm able to list all my WordPress shortcodes without PHP's Reflection API :)

tereško
  • 58,060
  • 25
  • 98
  • 150
Wordpressor
  • 7,173
  • 23
  • 69
  • 108

2 Answers2

0

hmm, I think this is a bad idea, but you can always do:

for($i = 1; $i < 4; $i++){
    require_once("functions".$i.".php");
}

But yeah, not a great idea ;)

snaderss
  • 159
  • 7
0

Why create an array of functions if you could have one (or more) static class with all these functions? You also can also write a function to include/require all files in a directory.

foreach (scandir(get_include_path() . 'DirectoryName') as $importDirFile) {             
    $pathinfo = pathinfo($importDirFile);
    #only php files
    if ($pathinfo['extension'] == 'php')
        require_once($importDir . $importDirFile);              
}
d3vkid
  • 11
  • 2