我想知道有什么区别$this->name
and $this->$name
?也确实$this
必须严格命名this或者它可以是任何东西吗?
$this
是保留变量名,不能用于其他任何用途。它特别指出您当前正在使用的对象。您必须使用$this
因为你不知道变量对象将被分配给什么。
$this->name
引用当前类的变量name
$this->$name
指的是类变量的任何值$name
是。因此
$name = "name";
echo $this->$name; // echos the value of $this->name.
$name = "test";
echo $this->$name; // echos the value of $this->test
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)