我需要有从数据库中获取内容的方法,但我不理解PHP中静态函数和普通函数之间的区别.
示例代码
class Item {
public static function getDetail($arg) {
$detail = $this->findProductId($arg);
return $detail;
}
private function findProductId($id) {
//find product_id in database where id = $arg
//return detail of product
}
}
Run Code Online (Sandbox Code Playgroud)
和课外的功能
function getDetail($arg) {
$detail = findProductId($arg);
return $detail;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用$item = Item::getDetail(15);和$item = getDetail(15);- 他们是一样的.