Do you think that I should keep all my php functions in one file?

I was wondering, do you think that I should keep all my functions in one file or separate them in different files !!

ps, if I put all the functions in one file, it would be easier for php to process this stuff !!

+3
source share
4 answers

It depends on how many functions they have, how long they work and what they do. For any significant project, putting everything in one file is usually a bad idea. They must be classified by what they do.

, , , .

+11

, , PHP script. , include , , .

+3

. , . , , , 0,01% , .

+2

For a very large project, the loss of speed will be offset by a modularity gain and, if done correctly, scalability. This function is very simple, very small and can be used to turn on any php and then execute it without the need for a long if () else or case switch. Now this may be more intense than the case switch statement, but for a large project, this function is ideal.

function trnFeature_getFeature($feature = 'default', $options = array()) {

    $path = __DIR__ . "/features/{$feature}/{$feature}";

    //Check the path, if no file exists bail out
    if(!file_exists($path . '.inc')) {
      return false;
    }

    //The path checked out, include the file
    include_once $path . '.inc';

    //setup the function that will execute the feature
    $feature_fn = "trnFeature_" . $feature . "_featureInit";

    //execute the function, passing it the $options array with all available options
    if(function_exists($feature_fn)) {
      $output = $feature_fn($options);
    } else {
      //you haven't created the correct function yet, so bail out
      return false;
    }

    return $output;
}
+1
source

Source: https://habr.com/ru/post/1765394/


All Articles