What does the variable $this mean in PHP?

前端 未结 10 1601

I see the variable $this in PHP all the time and I have no idea what it\'s used for. I\'ve never personally used it.

Can someone tell me how the variab

10条回答
  •  醉话见心
    2020-11-22 05:39

    It is the way to reference an instance of a class from within itself, the same as many other object oriented languages.

    From the PHP docs:

    The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

提交回复
热议问题