在PHP中,变量$这意味着什么?我看到了变量$this一直在PHP中,我不知道它是用来做什么的。我从未亲自使用过它,搜索引擎也忽略了$最后我搜索了“这个词。有人能告诉我$这个变量在PHP中是如何工作的吗?
3 回答
![?](http://img1.sycdn.imooc.com/545863c10001865402200220-100-100.jpg)
陪伴而非守候
TA贡献1757条经验 获得超8个赞
了解$thisphp中的变量是询问PHP是什么。不要问我们,问编译器:
print gettype($this); //object
print get_object_vars($this); //Array
print is_array($this); //false
print is_object($this); //true
print_r($this); //dump of the objects inside it
print count($this); //true
print get_class($this); //YourProject\YourFile\YourClass
print isset($this); //true
print get_parent_class($this); //YourBundle\YourStuff\YourParentClass
print gettype($this->container); //object
![?](http://img1.sycdn.imooc.com/533e4cde000148e602000200-100-100.jpg)
人到中年有点甜
TA贡献1895条经验 获得超7个赞
Class A{ public $myname; //this is a member variable of this classfunction callme() { $myname = 'function variable'; $this->myname = 'Member variable'; echo $myname; //prints function variable echo $this->myname; //prints member variable }}
function variable member variable
- 3 回答
- 0 关注
- 546 浏览
添加回答
举报
0/150
提交
取消