PHP學習筆記十八【建構函式】

來源:互聯網
上載者:User

標籤:style   blog   color   io   sp   div   on   log   cti   

<?php  class Person{    public $name;    public $age;    //定義建構函式 function 空格__construct   構造方法沒有傳回值,對象自動調用    public function __construct($iname,$iage){      $this->name=$iname; //$this:本質可以理解為這個對象的地址(對象的引用)      $this->age=$iage;    }        //建構函式方法第二種定義(方法名和類名一樣PHP4)    // public function Person(){      // echo "第二種構造方法";    // }  }  //建構函式在對象初始化的時候就會自動調用 // $p1=new Person();    $p2=new Person("張三",23);   echo $p2->name;    //PHP5的構造方法有兩種方式,PHP4隻支援後面那種  //當兩種方式同時存在的時候,優先調用__construct  //PHP中只能定義一個建構函式,如果沒定義的話就預設產生一個無參的構造方法?>

 

PHP學習筆記十八【建構函式】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.