天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php自動加載autoload機制示例分享

1,自定義函數

2,spl_autoload_register()

復制代碼 代碼如下:
liuyuan@ebuinfo:/var/www/phpgcs/php_autoload$ ll ./*
-rw-rw-r-- 1 liuyuan liuyuan  800 Feb 19 11:39 ./func_autoload.php
-rw-rw-r-- 1 liuyuan liuyuan  906 Feb 19 11:28 ./spl_autoload.php

./include:
total 16
drwxrwxr-x 2 liuyuan liuyuan 4096 Feb 19 11:42 ./
drwxrwxr-x 3 liuyuan liuyuan 4096 Feb 19 11:43 ../
-rw-rw-r-- 1 liuyuan liuyuan  142 Feb 19 11:42 aClass.php
-rw-rw-r-- 1 liuyuan liuyuan  143 Feb 19 11:42 bClass.php

首先看自定義函數方式:

復制代碼 代碼如下:
<?php
    define('EOL', (php_SAPI == 'cli') ? php_EOL : '</ br>');
    print_r(get_included_files());
    echo EOL;
    print get_include_path();
    echo EOL;
    //set_include_path(get_include_path().PATH_SEPARATOR.'/var/www/ly_php/php_spl/include/');
    //set_include_path(dirname(__FILE__).'/include');
    //set_include_path(dirname(__FILE__).'/include/');

    function __autoload($className){
        $filename = './include/'.$className.'.php';
        //$filename = './include/'.$className.'.php';
        //$filename = '/var/www/ly_php/php_spl/include/'.$className.'.php';
        if(file_exists($filename)){
            include_once $filename;
        }else{
            exit('no file');
        }
    }

    $a = new aClass();
    $b = new bClass();
    print_r(get_included_files());
?>

運行結果如下:

復制代碼 代碼如下:
liuyuan@ebuinfo:/var/www/phpgcs/php_autoload$ php func_autoload.php
Array
(
    [0] => /var/www/phpgcs/php_autoload/func_autoload.php
)

.:/usr/share/php:/usr/share/pear
aClass is loaded
bClass is loaded
Array
(
    [0] => /var/www/phpgcs/php_autoload/func_autoload.php
    [1] => /var/www/phpgcs/php_autoload/include/aClass.php
    [2] => /var/www/phpgcs/php_autoload/include/bClass.php
)

第二種方式:

復制代碼 代碼如下:
<?php
    class myLoader{
        public static function autoload($className){
            $filename = './include/'.$className.'.php';
            if(file_exists($filename)){
                include_once $filename;
            }else{
                exit('no file');
            }
        }
    }

    define('EOL', (php_SAPI == 'cli') ? php_EOL : '<br />');

    spl_autoload_register(array('myLoader', 'autoload'));

    /**
    *__autoload 方法在 spl_autoload_register 后會失效,因為 autoload_func 函數指針已指向 spl_autoload 方法
    * 可以通過下面的方法來把 _autoload 方法加入 autoload_functions list
    */
    //spl_autoload_register( '__autoload' );

 
    error_reporting(E_ALL^E_NOTICE^E_WARNING^E_ERROR);
    error_reporting(E_NOTICE | E_WARNING );

    $a = new aClass();
    print_r(get_included_files());
    echo EOL;
    $b = new bClass();
    echo EOL;
?>

運行結果如下:

復制代碼 代碼如下:
liuyuan@ebuinfo:/var/www/phpgcs/php_autoload$ php spl_autoload.php
aClass is loaded
Array
(
    [0] => /var/www/phpgcs/php_autoload/spl_autoload.php
    [1] => /var/www/phpgcs/php_autoload/include/aClass.php
)

bClass is loaded

php技術php自動加載autoload機制示例分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 哺乳溢出羽月希中文字幕 | 熟女久久久久久久久久久 | 亚洲黄色大片 | 色99蜜臀AV无码 | 中文字幕一区二区视频 | av狼新人开放注册区 | 久久综合九色 | 999视频在线观看 | 国产精品美女久久久久AV超清 | 99视频精品国产免费观看 | 18国产精品白浆在线观看免费 | 全部免费特黄特色大片看片 | 2019午夜75福利不卡片在线 | 成人18视频在线 | 直插下身完整的欧美版 | 日本2021免费一二三四区 | 久久青草热热在线精品 | 24小时日本高清免费看 | 亲爱的妈妈6韩国电影免费观看 | 久久久91精品国产一区二区 | 19不插片免费视频 | 欧美 亚洲综合在线一区 | 女人张开腿让男人添 | 亚洲日本欧美日韩高观看 | 久久久精品国产免费A片胖妇女 | 超碰在线97久久视频观看 | 国产精品人成视频免费999 | 毛片基地看看成人免费 | 一个人在线观看免费高清视频 | 亚洲国产成人精品久久久久 | 亚洲欧美综合中文 | 强奸日本美女小游戏 | 一边喂奶一边做边爱 | 国产成人无码视频一区二区三区 | 日日操天天操夜夜操 | 男人天堂2018亚洲男人天堂 | 用快播看黄的网站 | 最新高清无码专区在线视频 | 日产精品高潮呻吟AV久久 | 亚洲毛片网 | 超碰国产亚洲人人 |