<?PHPclass 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(); //3echo myclass::getcount(); //访问类里的方法 3echo $c1->getcount(); //3echo $c2->getcount(); //3echo $c3->getcount(); //3?>
로그인 후 복사
<?phpclass 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
로그인 후 복사