Skip to content
Advertisement

Create instances of all classes in a directory with PHP

I have a directory with several PHP files consisting of classes with the same names as the files. (Sample.php‘s class will be called Sample.)

Each of these classes have a function called OnCall().

How can I create an instance of every class in my directory and execute all of their OnCall()s?

I cannot do it manually ($sample = new Sample(); $sample->OnCall();, etc etc etc) because more classes will be added, edited and deleted by users.

Advertisement

Answer

Something like this ought to get the job done:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement