php向けの特性のパッケージについて
-
-
- Private
-
- Class star{
- public $name;
- private $age;
- private $weight;
-
-
-
- // , , ,
- function __struct($name,$age,$weight){
-
- $this->name=$name;
- $this->age=$age;
- $this->weight=$weight;
- }
-
-
-
- // ,
- private function __get($varName){
-
- return $this->$varName;
- }
-
-
- // , ,
- private function __set($varName,$strValue){
-
- return $this->$varName=$strValue;
- }
-
-
-
- // , isset() , __isset()
- private function __isset($strName){
-
- return isset($this->$strName);
-
- }
-
-
-
- // , unset() , __unset()
-
- private function __unset($strName){
-
- unset($this->$strName);//unset($var)
-
- }
-
-
- }
-
-
- $star=new star;
-
- echo $star->name;
- // ,
-
- $star->=" ";
- // ,
-
- isset($star->name);
- // isset()
-
- unset($star->name);
- // unset()
-
-
- ///////////// ///////////////
-
- echo $star->age; //return error
- //
-
- $star->age="30";//return error
- // ,
-
-
- echo isset($star->weight); //return error
- //
-
- unset($star->weight); //return error
- //
-
-
- ////////////////// , //////////////////////////
-
- // , __get()
- echo $star->age;
-
-
- // , , __set()
- $star->weight="65kg";
-
-
- // , isset() , __isset()
- isset($star->age);
-
-
- // , unset() , __unset()
- unset($star->weight);
本文は“私のPHPの道”のブログから出て、転載して作者と連絡してください!