0
当使用代码点火器时,我创建了很多看起来像这样的函数;在if语句中赋值?
function info($id){
$r = $this->db->select('id', 'name', 'age')->from('users')->where('id', $id)->get();
return ($r->num_rows() == 0 ? false : $r->result());
}
现在,当我使用这个功能我也用这个功能来检查用户是否存在,并将其分配给一个变量。
那么它将被用于类似
if(($user = $this->user->info($_GET['id'])) === false)
die('User not found');
//now we can continue and $user contains the user info
我的问题是,没有任何理由,这是一个坏主意?
据我所知,这是一样的
$user = $this->user->info($_GET['id']);
if($user === false)
die('User not found');
,但我实际上认为更容易执行。