<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 1、下面是全局變量使用: ~~~ <?php //定義,全局變量 global $global_nums; //賦值 $global_nums=0; class Child{ public $name; function __construct($name){ $this->name=$name; } public function join_game(){ global $global_nums; $global_nums+=1; echo $this->name."加入堆雪人游戲<br/>"; } } //創建3個小孩 $child1=new Child("aaa"); $child1->join_game(); $child2=new Child("bbb"); $child2->join_game(); $child3=new Child("ccc"); $child3->join_game(); echo $global_nums; ?> ~~~ 注意:全局變量只能先定義,再進行初始化,不能直接初始化,或初始化和定義寫到一起。 2、static 靜態變量使用 ~~~ <?php class Child{ public $name; public static $nums=0; function __construct($name){ $this->name=$name; } public function join_game(){ //類內部訪問 2中如下 //Child::$nums+=1; self::$nums+=1; echo $this->name."加入堆雪人游戲<br/>"; } } //創建3個小孩 $child1=new Child("aaa"); $child1->join_game(); $child2=new Child("bbb"); $child2->join_game(); $child3=new Child("ccc"); $child3->join_game(); $child4=new Child("ddd"); $child4->join_game(); //外部訪問 echo Child::$nums; ?> ~~~ 靜態變量只能定義在類中,使該類的所有對象共享的變量,任何一個該類的對象去訪問他時,取到的數值都是一樣的,同樣任何一個該類的變量去修改他時,修改的都是同一個變量。 如何訪問靜態變量: 在類外部:類名::$類變量名 在類內部:self::$類變量名 ?或者 ? 類名::$類變量名 具體在內存的分配情況見下圖: ![](https://box.kancloud.cn/2016-06-03_5750fd8e34ddc.jpg) ### 下面是簡單的實例,加深對上面的理解: ~~~ <?php /* //第一種情況 class Person{ public static $a=90; } echo Person::$a; // 輸出不會報錯打印:90 */ /* //第二種情況“ class Person{ public static $a=900; public function __construct(){ $this->a=45;//(1) } } echo Person::$a; //不會報錯,輸出900;(1)寫法是錯誤的,但是因為沒有創建對象, //所以不會被調用,也就不會出錯~ */ //第三種情況“ class Person{ public static $a=9011; public function __construct(){ $this->a=45;//(1) } } $p1=new Person(); echo Person::$a; //;(1)寫法是錯誤的,但是因為創建了對象,被調用 ?> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看