zoukankan      html  css  js  c++  java
  • PHP之autoload理解

    举个例子就可以看懂了:

    同一目录中有2个文件index.php和test.php,在test.php中定义一个test类。

    test.php

    <?php
    
    class  test{
    
        public function __construct()
        {
            echo 'hello world';
        }
    
    }

    index.php

    <?php
    
    
    spl_autoload_register($name){
       require "$name.php";
    }
    $test = new test();

    尽管 __autoload() 函数也能自动加载类和接口,但更建议使用 spl_autoload_register() 函数。

    spl_autoload_register() 提供了一种更加灵活的方式来实现类的自动加载(同一个应用中,可以支持任意数量的加载器,比如第三方库中的)。

  • 相关阅读:
    正向代理与反向代理
    uniapp
    js
    js
    uniapp
    uniapp
    uniapp
    uniapp
    关于资源获取(请把https改为http)
    uniapp
  • 原文地址:https://www.cnblogs.com/shaoyikai/p/4493638.html
Copyright © 2011-2022 走看看