復制代碼 代碼如下:
<?php
class Counter
{
private static $count = 0;//定義一個靜態屬性
const VERSION = 2.0;//定義一個常量
//構造函數
function __construct()
{
self::$count++;
}
//析構函數
function __destruct()
{
self::$count--;
}
//定義一個靜態的方法
static function getCount()
{
return self::$count;
}
}
//創建一個實例
$c = new Counter();
//執行打印
print( Counter::getCount(). "<br>/n" ); //使用直接輸入類名來訪問靜態方法Counter::getCount
//打印類的版本
print( "Version useed: " .Counter::VERSION. "<br>/n" );
?>
新聞熱點
疑難解答