1.我定义了一个AR基类,里面代码如下:
abstract class AR extends \PDO {
abstract public function from($tableName = '');
abstract public function where($condition = []);
abstract public function addWhere($condition = []);
abstract public function orderBy($orderBy = []);
abstract public function groupBy($groupBy = []);
abstract public function having($condition = []);
}
2.又写了一个子类DB,集成AR。
class db extends AR {
public function select($field = [])
{
// TODO: Implement select() method.
return $this;
}
public function from($tableName = '')
{
// TODO: Implement from() method.
return $this;
}
public function where($condition = [])
{
// TODO: Implement where() method.
return $this;
}
public function addWhere($condition = [])
{
// TODO: Implement andWhere() method.
return $this;
}
public function groupBy($groupBy = [])
{
// TODO: Implement groupBy() method.
return $this;
}
public function orderBy($orderBy = [])
{
// TODO: Implement orderBy() method.
return $this;
}
public function having($condition = [])
{
// TODO: Implement having() method.
return $this;
}
}
抽象方法的具体实现里,都返回了本身。
3.现在我在控制器文件里实例化db类,发现能正常调用 $this->db->select()->from()->where()->queryAll();
运行不报错。queryAll
里可以进行操作。
phpStorm不能识别queryAll方法返回值,给不了提示。


添加注解后, phpstorm可以自动识别