我想模块化的功能,但是这是行不通的短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