出现错误:调用未定义的函数tim() 我该如何解决这个问题?
public function SelectEmailLimit(){
$stmt = $this->conn->prepare("SELECT fname, mname, lname, created_at FROM ms_membership ORDER BY id DESC LIMIT 4");
$stmt->execute();
$row =array();
$stmt->bind_result($fname, $mname, $lname,$created);// can write any name to bind the result shouldnot be same as table row name
while ($stmt->fetch())
{
$create =tim($created);
$row[] = array(
'fname' => $fname,
'mname' => $mname,
'lname' => $lname,
'created' => $create
);
}
function tim($created){
return me;
}
$stmt->close();
return $row;
}
答案 0 :(得分:4)
PHP没有函数范围,因此“函数内的函数”不是“一件事”。当首次点击该行代码时,function tim
将动态定义 全局 。这意味着:
SelectEmailLimit
,PHP将尝试两次定义该函数,这将导致错误。PHP唯一与你想要的东西是匿名函数:
$tim = function ($created) { return me; };
...
$create = $tim($created);
这些你显然也需要在打电话之前定义。