2

Would it be a good idea to include extensions for a script this way?

for eg. using glob to get a list of php files from a certain directory, and do a require_once for each file.

this would run each time the page is generated. would it be bad for performance?

David
  • 208,112
  • 36
  • 198
  • 279
Alex
  • 66,732
  • 177
  • 439
  • 641

3 Answers3

2

It would be bad for two reasons:

  1. If someone sticks evil.php in your directory it could be included and executed.
  2. glob is not the most efficient, nor is including via a relative path.

Perhaps look into using autoloading.

mfonda
  • 7,873
  • 1
  • 26
  • 30
1

You might consider using __autoload() instead.

1

It isn't particularly good practise: you're including files irrespective of whether you need them or not. Nor can you control the order of including/requiring to handle any dependencies between the files. If these are PHP class files, then using an autoloader would be a better option.

Mark Baker
  • 209,507
  • 32
  • 346
  • 385