get_class_methods($object)显示存在fetchAll方法,但是$object->fetchAll()却报错?难道这是php的bug
1. 运行环境
win10 + PHP Version 5.4.19 + apache2.4
2.软件环境
使用的是 zentao 8.1.3 的一个软件管理系统
3. 问题描述
进行db查询的时候报错如下
查询代码:
$this->dao->select('*')->from('zt_structrue_task_dispatch')->fetchAll()
报错
Fatal error: Call to a member function fetchAll() on a non-object
并且报错的时候,我用下列代码判断是否存在该方法,显示是存在fetchAll方法的
$query = $this->dao->select('*')->from('zt_structrue_task_dispatch');
if (in_array('fetchAll',get_class_methods($query))){
dd($query->fetchAll());
}
但是是下列的查询则不会报错
$this->dao->select('id')->from('zt_structrue_task_dispatch')->fetchAll()
$this->dao->select('*')->from('zt_user')->fetchAll()
有没有朋友遇到过的 敬请指教
使用get_class 显示类名为dao
然后在dao类下 能查到fetchAll 方法,代码如下
/**
* 获取所有记录。
* Fetch all records.
*
* @param string $keyField 返回以该字段做键的记录
* the key field, thus the return records is keyed by this field
* @access public
* @return array the records
*/
public function fetchAll($keyField = '')
{
$stmt = $this->query();
if(empty($keyField)) return $stmt->fetchAll();
$rows = array();
while($row = $stmt->fetch()) $rows[$row->$keyField] = $row;
return $rows;
}
推荐文章: