服务器之家

服务器之家 > 正文

php 类自动载入的方法

时间:2020-09-27 16:07     来源/作者:PHP教程网

php 类自动载入方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
class inload
{
/**
   * 类自动载入,不需要由开发者调用
   *
   * @param string $class 类文件
   */
  private function autoload( $class )
  {
    if( empty($class) )
    {
      throw new QException('加载文件不存在'.$class);
    }
    else
    
      require _SPRING_.'/_Core/SpringMap.php'; //框架地图
      if(! file_exists( $source[$class]['file'] ) )
      {
        throw new QException('加载文件不存在'.$class);
      }
      require $source[$class]['file'];
    }
  }
   
  /**
   * 注册或取消注册一个自动类载入方法
   *
   * 该方法参考 Zend Framework
   *
   * @param string $class 提供自动载入服务的类
   * @param boolean $enabled 启用或禁用该服务
   */
  private function registerAutoload($class = 'Interpreter' , $enabled = true)
  {
    if (!function_exists('spl_autoload_register'))
    {
      throw new QException('spl_autoload 不存在这个PHP的安装');
    }
    if ($enabled === true)
    {
      spl_autoload_register(array($class, 'autoload'));
    }
    else
    {
      spl_autoload_unregister(array($class, 'autoload'));
    }
  }
   
  /**
  * 析构函数
  */
  public function __destruct()
  {
    self::registerAutoload('Interpreter' , false);
  

以上所述就是本文的全部内容了,希望大家能够喜欢。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址 2020-08-12
最新idea2020注册码永久激活(激活到2100年)
最新idea2020注册码永久激活(激活到2100年) 2020-07-29
返回顶部