- コンストラクタは
- PHP4 function クラス名()
- PHP5 function __construct()。
- デストラクタ
- PHP4 存在しない
- PHP5 function void __destruct ( void )。
- メンバ関数を自分で使うときは$this->が必要。
- メンバ変数も$this->startTime という感じで使う。
例
class ProcessTime { var $startTime; /* * 現在の時間を、マイクロ秒単位で取得 * PHP4, 5 互換 * PHP5 以上なら、 microtime(true); で同じ結果が取得できる */ function getMicrotime() { list($msec, $sec) = explode(" ", microtime()); return ((float)$sec + (float)$msec); } function __construct() { $this->startTime = $this->getMicrotime(); // PHP4,5 互換 } function output() { // 計測完了時の時間を格納 $endTime = $this->getMicrotime(); // PHP4,5 互換 print '<p>'.number_format($endTime - $this->startTime, 7).'micro sec</p>'; } };