Blogger Information
Blog 20
fans 0
comment 0
visits 8105
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类的自动加载器
P粉191340380
Original
343 people have browsed it

自动加载器 autoloader.php

  1. spl_autoload_register(function($class){
  2. require $class. '.php';
  3. });

a.php

  1. namespace zuoye\controller;
  2. class a
  3. {
  4. public static function index()
  5. {
  6. return __METHOD__;
  7. }

b.php

  1. namespace zuoye\controller;
  2. class b
  3. {
  4. public static function index()
  5. {
  6. return __METHOD__;
  7. }

c.php

  1. namespace zuoye\controller;
  2. class c
  3. {
  4. public static function index()
  5. {
  6. return __METHOD__;
  7. }

入口文件 zuoye.php

  1. namespace zuoye;
  2. require __DIR__ . '/controller/a.php';
  3. require __DIR__ . '/controller/b.php';
  4. require __DIR__ . '/controller/c.php';
  5. echo controller\a::index().'<br>';
  6. echo controller\b::index().'<br>';
  7. echo controller\c::index().'<br>';
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!