php中这里的几个$this怎么理解?
答案:6 悬赏:70
解决时间 2021-01-25 01:28
- 提问者网友:浪荡绅士
- 2021-01-24 00:57
php中这里的几个$this怎么理解?
最佳答案
- 二级知识专家网友:爱难随人意
- 2021-01-24 02:18
oop 面向对象化程序容易见面 $this 这个指的就是当前对象
比如 :
class User {
// 这里的 username 就是此类{ 对象 } 的成员 { 属性 }
private $username;
public function __construct($username='')
{
if($username!=null && trim($username)!=''){
$this->username = $username;
}
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
// 那么说这里写的 $this 就是指当前对象
// 读取当前对象的成员 username 并把 $username 值 给此成员
$this->username = $username;
}
}
比如 :
class User {
// 这里的 username 就是此类{ 对象 } 的成员 { 属性 }
private $username;
public function __construct($username='')
{
if($username!=null && trim($username)!=''){
$this->username = $username;
}
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
// 那么说这里写的 $this 就是指当前对象
// 读取当前对象的成员 username 并把 $username 值 给此成员
$this->username = $username;
}
}
全部回答
- 1楼网友:一把行者刀
- 2021-01-24 07:55
感觉好深奥的样子
- 2楼网友:迷人又混蛋
- 2021-01-24 07:11
this英文就是“这个”的意思,
- 3楼网友:几近狂妄
- 2021-01-24 06:28
$是变量的意思
- 4楼网友:三千妖杀
- 2021-01-24 05:28
当前类的对象
- 5楼网友:不甚了了
- 2021-01-24 03:51
$this表示当前类。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯