>  기사  >  백엔드 개발  >  求问下这个 Call to undefined function int()的原因

求问下这个 Call to undefined function int()的原因

WBOY
WBOY원래의
2016-06-23 14:10:391206검색

public static function getById($uid){
    $user = new User;
    $sql = sprintf('SELECT username, password, email_add, is_active, perm  FROM  %suser  WHERE user_id = %d',DB_TB_PREFIX, mysql_real_escape_string($uid));
    $query = mysql_query($sql);
    if(mysql_num_rows($query) && $res = mysql_fetch_assoc($query)){
        $user->uid = int($uid);// 注意这里用了int
        $user->username = $res['username'];
        $user->password = $res['password'];
        $user->isActive = $res['is_active'];
        $user->emailAddr = $res['email_add'];
        $user->perm = $res['perm'];
    }

    return $user;
}

当我在另一个页面
$user = User::getById($_SESSION['uid']);// $_SESSION['uid']是存在的

报错 Call to undefined function int();

请问是什么原因?


回复讨论(解决方案)

是不是括号错了。。。
不是应该这样写吗  $b = (int)$a

    $user->uid = int($uid);//注意这里用了int
换成
 $user->uid = intval($uid);//

这个 Call to undefined function int()的原因?
php 没有提供名为 int 的函数,当然就是未定义了

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.