php向けの特性のパッケージについて



  
  
  
  
  1.  
  2.  
  3. Private 
  4.  
  5. Class star{ 
  6. public $name
  7. private $age
  8. private $weight
  9.  
  10.  
  11.  
  12. // , , ,  
  13. function __struct($name,$age,$weight){ 
  14.     
  15.      $this->name=$name
  16.      $this->age=$age
  17.      $this->weight=$weight
  18.  
  19.  
  20.  
  21. // ,  
  22. private function __get($varName){ 
  23.  
  24.      return $this->$varName
  25.  
  26.  
  27. // , ,  
  28. private function __set($varName,$strValue){ 
  29.  
  30.      return $this->$varName=$strValue
  31.  
  32.  
  33.  
  34. //   , isset() , __isset() 
  35. private function __isset($strName){ 
  36.  
  37.      return isset($this->$strName); 
  38.  
  39.  
  40.  
  41.  
  42. // , unset() , __unset()  
  43.  
  44. private function __unset($strName){ 
  45.  
  46.     unset($this->$strName);//unset($var)  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. $star=new star; 
  53.  
  54. echo $star->name; 
  55. // ,  
  56.  
  57. $star->=" "
  58. // ,  
  59.  
  60. isset($star->name); 
  61. // isset()  
  62.  
  63. unset($star->name); 
  64. // unset()  
  65.  
  66.  
  67. ///////////// /////////////// 
  68.  
  69. echo $star->age; //return error 
  70. //  
  71.  
  72. $star->age="30";//return error 
  73. // ,  
  74.  
  75.  
  76. echo isset($star->weight);  //return error 
  77. //  
  78.  
  79. unset($star->weight); //return error 
  80. //
  81.  
  82.  
  83. ////////////////// , ////////////////////////// 
  84.  
  85. // , __get()  
  86. echo $star->age; 
  87.  
  88.  
  89. // , , __set()  
  90. $star->weight="65kg"
  91.  
  92.  
  93. // , isset() , __isset()  
  94. isset($star->age); 
  95.  
  96.  
  97. // , unset() , __unset()  
  98. unset($star->weight); 

 
本文は“私のPHPの道”のブログから出て、転載して作者と連絡してください!