1

I have a bunch of php files

each file contains one function

no class

no namespace

just global functions.

How can I load those files easily with composer? with psr-4 autoloader or any similar option so I don't have to require() all the time all files

Toskan
  • 13,911
  • 14
  • 95
  • 185
  • 3
    Auto-loading is for classes, not global functions. There are some good suggestions in this question https://stackoverflow.com/questions/4737199/autoloader-for-functions especially the one from user _ivoba_ – Scuzzy Oct 30 '17 at 21:48

1 Answers1

2

Composer has support for autoloading functions. The only caveat is the functions are always included, they aren't loaded on demand.

{
    "autoload": {
        "files": ["src/MyLibrary/functions.php", "foo/bar/baz.php"]
    }
}

https://getcomposer.org/doc/04-schema.md#files

aknosis
  • 3,602
  • 20
  • 33