Blogger Information
Blog 25
fans 0
comment 0
visits 10608
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类的自动加载
PHui
Original
301 people have browsed it
  1. <?php
  2. // 类的自动加载
  3. namespace load;
  4. spl_autoload_register(function ($class) {
  5. // 类名
  6. $path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
  7. // 类文件名
  8. $file = __DIR__ . '/' . $path . '.php';
  9. if (is_file($file) && file_exists($file)) {
  10. require $file;
  11. } else {
  12. die($file . '不存在');
  13. }
  14. });
  15. use admin\controller\Index;
  16. use admin\model\User;
  17. use admin\view\index\Hello;
  18. echo Index::show() . PHP_EOL;
  19. echo User::show() . PHP_EOL;
  20. echo Hello::show() . PHP_EOL;

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post