Blogger Information
Blog 62
fans 3
comment 1
visits 29746
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php自动加载器的用法
kiraseo_wwwkiraercom
Original
404 people have browsed it

php自动加载器的用法

代码 zuoye.php

  1. <?php
  2. namespace api;
  3. // 引入类的自动加载器
  4. require 'api/auooloader.php';
  5. $res_1 = new controller\D1();
  6. $res_2 = new controller\D2();
  7. $res_3 = new controller\D3();
  8. echo $res_1->index();
  9. echo '<hr/>';
  10. echo $res_2->one();
  11. echo '<hr/>';
  12. echo $res_3->index_all();

代码 auooloader.php

  1. <?php
  2. // 自动加载器
  3. spl_autoload_register(function ($class) {
  4. require $class.'.php';
  5. });

代码 D1.php

  1. <?php
  2. namespace api\controller;
  3. class D1
  4. {
  5. public function index(){
  6. return __CLASS__.'类'.__METHOD__.'方法';
  7. }
  8. }

代码 D2.php

  1. <?php
  2. namespace api\controller;
  3. class D2
  4. {
  5. public function one(){
  6. return __CLASS__.'类'.__METHOD__.'方法';
  7. }
  8. }

代码 D3.php

  1. <?php
  2. namespace api\controller;
  3. class D3
  4. {
  5. public function index_all(){
  6. return __CLASS__.'类'.__METHOD__.'方法';
  7. }
  8. }

目录解构

输出结果

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