av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

解析PHP5析構(gòu)函數(shù)的具體使用方法

在升級版的PHP5中,都有構(gòu)造函數(shù)與PHP5析構(gòu)函數(shù)。但是在具體的實(shí)際操作中,他們的功能和使用方式已經(jīng)和普通的函數(shù)方式有所不同。每當(dāng)實(shí)例化一個類對象時,都會自動調(diào)用這個與類同名的函數(shù),使對象具有與生俱來的一些特征。

#t#在PHP5中,則使用__construct()來命名構(gòu)造函數(shù),而不再是與類同名,這樣做的好處是可以使構(gòu)造函數(shù)獨(dú)立于類名,當(dāng)類名改變時,不需要在相應(yīng)的去修改構(gòu)造函數(shù)的名稱。

與構(gòu)造函數(shù)相反,在PHP5中,可以定義一個名為__destruct()的函數(shù),稱之為PHP5析構(gòu)函數(shù),PHP將在對象在內(nèi)存中被銷毀前調(diào)用析構(gòu)函數(shù),使對象在徹底消失之前完成一些工作。對象在銷毀一般可以通過賦值為null實(shí)現(xiàn)。

 
 
 
  1.  
  2. /*  
  3.  * Created on 2009-11-18  
  4.  *  
  5.  * To change the template for this generated file go to  
  6.  * Window - Preferences - PHPeclipse - PHP - Code Templates  
  7.  */  
  8.  class student{  
  9.   //屬性  
  10.   private $no;  
  11.   private $name;  
  12.   private $gender;  
  13.   private $age;  
  14.     
  15.   private static $count=0;  
  16.   function __construct($pname)  
  17.   {  
  18.    $this->name = $pname;  
  19.    self::$count++;  
  20.   }  
  21.     
  22.   function __destruct()  
  23.   {  
  24.    self::$count--;  
  25.   }  
  26.     
  27.   static function get_count()  
  28.   {  
  29.    return self::$count;  
  30.   }  
  31.  }  
  32.    
  33.  $s1=new student("Tom");  
  34.  print(student::get_count());  
  35.    
  36.  $s2=new student("jerry");  
  37.  print(student::get_count());  
  38.    
  39.  $s1=NULL;  
  40.  print(student::get_count());  
  41.    
  42.  $s2=NULL;  
  43.  print(student::get_count());  
  44. ?> 

上面這段代碼就是PHP5析構(gòu)函數(shù)的具體使用方法,希望對大家有所幫助。


分享名稱:解析PHP5析構(gòu)函數(shù)的具體使用方法
文章轉(zhuǎn)載:http://uogjgqi.cn/article/djheohc.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流