开发者

Scanning directory for php files, and include them in the current script

开发者 https://www.devze.com 2023-02-06 16:46 出处:网络
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.

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 e开发者_StackOverflowach time the page is generated. would it be bad for performance?


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.


You might consider using __autoload() instead.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消