有人能告诉我我做错了什么吗?这是我第一次使用__toString.我收到以下错误:可捕获的致命错误:方法users_class :: __ toString()必须返回一个字符串值
原文链接:https://www.f2er.com/php/130934.html这是我使用Smarty调用对象:
{assign var='udatas' value="$userObj->fetchUser(array('id'=>$ststres[ststval].to_id))"}
这是对象.
class users_class { protected $users_class; public function __toString() { return $this->users_class; } public function fetchUser(array $conditions){ $db = Core::getInstance(); $sql = "SELECT * FROM ".USERS." WHERE "; $i=0; $params = array(); //$where = array(); foreach ($conditions as $column => $value) { if (preg_match('/^[a-z-.-_]+$/',$column)) { if($i!=0){ $sql .= " AND "; } $sql .= "$column = ?"; $params[] = $value; $i++; } } //$sql .= implode(' AND ',$where); //$sql .= " order by title asc"; $res = $db->dbh->prepare($sql); $res->execute(array_values($params)); return $res->fetch(PDO::FETCH_ASSOC); } }