函式名稱: BaseResult::getWarningsCount()
適用版本: 該函式在 PHP 5.3.0 及以上版本中可用。
用法: BaseResult::getWarningsCount() 是一個類方法,用於獲取BaseResult物件中的警告計數。
示例:
<?php
class BaseResult {
private $warningsCount;
public function __construct($count) {
$this->warningsCount = $count;
}
public function getWarningsCount() {
return $this->warningsCount;
}
}
$result = new BaseResult(3);
$warningsCount = $result->getWarningsCount();
echo "警告計數: " . $warningsCount;
?>
輸出:
警告計數: 3
在以上示例中,我們首先定義了一個名為 BaseResult 的類,該類包含一個私有屬性 $warningsCount
,並在建構函式中初始化該屬性。
然後,我們定義了一個 getWarningsCount()
方法,用於返回 $warningsCount
屬性的值。
在主程式中,我們建立了一個BaseResult物件,並將警告計數設定為 3。然後,透過呼叫 getWarningsCount()
方法,我們獲取警告計數的值並列印出來。