Scanning directory for php files, and include them in the current script
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:
- If someone sticks
evil.php
in your directory it could be included and executed. 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.
精彩评论