类自动加载封装类

 1 <?php
 2 
 3 class Common {
 4     /**
 5      * 可以实现类文件的加载
 6      */
 7     public static function  autoload($class_name) {
 8         include './' . $class_name . '.class.php';
 9     }
10     /**
11      * 注册自动加载方法
12      */
13     public function register() {
14         // spl_autoload_register(array($this, 'autoload'));
15         spl_autoload_register("self::autoload");
16     }
17     /**
18      * 构造方法
19      */
20     public function __construct() {
21         // 注册自动加载方法
22         $this->register();
23     }
24 }

使用方法

1 include './Common.php';
2 $obj = new Common;
原文地址:https://www.cnblogs.com/mrszhou/p/7554773.html