Home  >  Article  >  Backend Development  >  PHP面向对象static和const的两段代码示例

PHP面向对象static和const的两段代码示例

WBOY
WBOYOriginal
2016-06-20 12:50:41828browse

<?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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn