• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. php中namespace use用法例子分析

        時間:2024-06-13 21:40:04 PHP 我要投稿
        • 相關推薦

        php中namespace use用法例子分析

          class把一個一個function組織起來,namespace可以理解成把一個一個class,function等有序的組織起來。個人覺得,namespace的主要優勢有

          第一,可以更好的管理代碼

          第二,文件一多,可以避免class,function的重名

          第三,代碼可讀性增強了

          1. 定義namespace

          namespace userCenter;//php代碼namespace userCenterregister;//php代碼namespace userCenterlogin { //php代碼}

          命名空間不能嵌套或在同一代碼處聲明多次(只有最后一次會被識別)。但是,你能在同一個文件中定義多個命名空間化的代碼,比較合適的做法是每個文件定義一個命名空間(可以是相同命名空間)。

          2. 調用namespace

          userCenterregister; //絕對調用userCenterlogin; //相對調用use userCenterregister; //引用空間use userCenterregister as reg; //引用空間并加別名

          3. 實例說明

          login.class.php

          regist.class.php

          test.php

          <"login.class.php";require use="" usercenterregist="" as="" echo="" login="new" login-="">save();echo registcheck_username(); //相對調用echo regcheck_username(); //別名調用$regist = new regregist();echo $regist->save();

          使用use,比絕對調用要好一點,好比給class,function等加了一個前綴,這樣看起來就比較清楚了。

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【php中namespace use用法例子分析】相關文章:

        簡單分析PHP中序列化用法介紹08-15

        PHP防止SQL注入的例子09-25

        php中dirname()和--FILE--常量的用法09-26

        PHP中的排序函數區別分析08-23

        PHP中MySQL、MySQLi和PDO的用法和區別07-01

        簡單介紹php構造函數用法08-31

        PHP對象注入的實例分析08-27

        商務禮儀的案例分析經典例子06-21

        PHP中curl的使用實例07-31

        PHP中關于類的定義10-02

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 日本乱理伦片中文 | 亚洲最大国产综合91 | 日本天堂免费网站在线观看 | 日本中文字幕在线看 | 日韩亚洲欧美国产动漫在线观看 | 欧美视频精品一区二区 |

            php中namespace use用法例子分析

              class把一個一個function組織起來,namespace可以理解成把一個一個class,function等有序的組織起來。個人覺得,namespace的主要優勢有

              第一,可以更好的管理代碼

              第二,文件一多,可以避免class,function的重名

              第三,代碼可讀性增強了

              1. 定義namespace

              namespace userCenter;//php代碼namespace userCenterregister;//php代碼namespace userCenterlogin { //php代碼}

              命名空間不能嵌套或在同一代碼處聲明多次(只有最后一次會被識別)。但是,你能在同一個文件中定義多個命名空間化的代碼,比較合適的做法是每個文件定義一個命名空間(可以是相同命名空間)。

              2. 調用namespace

              userCenterregister; //絕對調用userCenterlogin; //相對調用use userCenterregister; //引用空間use userCenterregister as reg; //引用空間并加別名

              3. 實例說明

              login.class.php

              regist.class.php

              test.php

              <"login.class.php";require use="" usercenterregist="" as="" echo="" login="new" login-="">save();echo registcheck_username(); //相對調用echo regcheck_username(); //別名調用$regist = new regregist();echo $regist->save();

              使用use,比絕對調用要好一點,好比給class,function等加了一個前綴,這樣看起來就比較清楚了。