【发布时间】:2013-11-16 03:31:17
【问题描述】:
我有以下代码,运行时返回此错误:
PHP 致命错误:在第 36 行的 /classes/User.php 中的非对象上调用成员函数 count()
public function find($user = null) {
if($user) {
$field = (is_numeric($user)) ? 'id' : 'email';
$data = $this->_db->get('*', 'users', array($field, '=', $user));
if($data->count()) { // This is line 36, the $_db variable is an instance of the DB class
$this->_data = $data->first();
return true;
}
}
return false;
}
我错过了什么让 $data 不引用对象?
【问题讨论】:
-
错误消息与
$_db变量无关。关于$data。查看您的->_db->get()方法的文档以了解它是否应该返回一个对象。
标签: php oop object count instance