Calling php functions from a separate file.

There are a bunch of php functions that are used on different pages. I collected them in a separate file and included them in the necessary places with include. Is it possible to somehow do without inclusion? Like java scripts?

Answer 1, authority 100%

1) Break the functions into several files, or better yet, wrap them in classes

2) Include them as needed with require_once

Alternatively, you can use your own list of connected files to speed up (require_once is recommended to be used in extreme cases, because it is slow)

function incfile($f) {
  if (!isset($_ENV['included'])) $_ENV['included'] = array();
  if (!empty($_ENV['included'][$f])) return true;
  require $f;
  $_ENV['included'][$f] = 1;
  return true;

Answer 2

Unless you send get or post requests, and process them in a file with functions.
But this is stupid .. what did the inclusion not please?

Answer 3

If you only care about the result of executing that function, then kenpachi’s version is fine.
As an option, use require(), the fact is that this function, regardless of its position in the file, includes the necessary file at the very beginning and thus works several times faster than includ‘a.

Answer 4

Wrap functions in classes, break functions into separate classes. And read about the function – __autoload.