<?PHP class myclass{ static $count; //静态化类属性 function __construct(){ self::$count++; //static声明的部分用self访问 } static function getcount(){ return self::$count; } } myclass::$count=0; //属性的初始化 $c1=new myclass(); //1 $c2=new myclass(); //2 $c3=new myclass(); //3 echo myclass::getcount(); //访问类里的方法 3 echo $c1->getcount(); //3 echo $c2->getcount(); //3 echo $c3->getcount(); //3 ?>
<?php class myclass{ const VALUE="dongdong11019"; function showvalue(){ return self::VALUE; } public function getvalue(){ return $this->showvalue(); } } echo myclass::VALUE; ECHO "<hr/>"; $class1=new myclass(); echo $class1->getvalue(); ?> //dongdong11019 //dongdong11019
时间: 2024-10-15 06:43:40