Including a whole directory in PHP or Wildcard for use in PHP Include?

后端 未结 5 620
粉色の甜心
粉色の甜心 2021-01-12 07:30

I have a command interpreter in php. It lives inside the commands directory and needs access to every command in the command file. Currently I call require once on each co

5条回答
  •  自闭症患者
    2021-01-12 08:04

    foreach (glob("*.php") as $filename) {
        require_once $filename;
    }
    

    I'd be careful with something like that though and always prefer "manually" including files. If that's too burdensome, maybe some refactoring is in order. Another solution may be to autoload classes.

提交回复
热议问题