有人可以告诉我我做错了什么吗?这是我第一次使用 __toString。我收到以下错误:Catchable fatal error: Method users_class::__toString() must return a string value
这是我使用 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);
}
}