什么是“$ this”在php? [英] what is "$this" in php?

查看:141
本文介绍了什么是“$ this”在php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP中的变量$ this是什么意思?




b $ b

我知道这是非常基本的。我在YouTube上看到关于CakePHP和PHP的教程,他们都在使用$ this,但没有人实际上说它是什么或用于什么。我认为它是一个变量,但它包含什么,为什么所有的函数必须从它运行?是当前类吗?我阅读了这里,$ this与自己不同,因此我不确定

I know this is extremely basic. I am watching tutorials on YouTube about CakePHP and PHP and all of them keep using "$this", but none of them actually say what it is or what it is used for. I think it is a variable, but what does it contain, and why do all of the functions have to be run from it? Is it the current class? I read here that "$this" is different from self though, so I am not sure if this is the case.

推荐答案

如果在类中使用, $ this 指的是它所在的对象。

if used in a class, $this refers to the object that it's in.

这篇关于什么是“$ this”在php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆