我想模塊化的功能,但是這是行不通的短PHP函數...如何編寫共同努力
class Review {
public function show_report($db, $id){
// Query the DB on $id
$x = $this->get_survey($db, 1);
$y = $this->get_survey($db, 2);
// Use x and y to build a report
return $a_report;
}
private function get_survey($db, $n){
// Query the DB for a certain survey number
if($n == 1){
// Perform some logic
} else {
// Perform some other logic
}
return $a_survey;
}
};
使用這樣的類..
<?php
include_once('api/Review.class.php');
$r = new Review();
?>
<p>
<?php
echo Review::show_report($db, $id);
?>
</p>
PHP拋出這個:
Fatal error: Using $this when not in object context in Review.class.php
感謝您的幫助!
現在我得到了'致命錯誤:當不在42行的Review.class.php中的對象上下文中時使用$ this' – broinjc
您能否發佈完整的代碼,因爲在示例代碼中沒有聲明變量? – David
我試圖抽象出一些細節(這是一個很長的文件),這樣做的準確性我就搞砸了。我的錯。好建議! – broinjc