开发者

what does $this mean within a class definition? [closed]

开发者 https://www.devze.com 2023-01-17 01:55 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about programming within the scope defined in the help center.

Closed 9 years ago.

Improve this question

As I continue to try and improve myself as a junior PHP developer, I have started to try break down other peoples work. I find it helps me understand, as well as giving me ideas.

Two things I do not get, in a PHP class, what $this means, and what array($this,'some_function') means when I would expect a function name in it's place.

Many thanks开发者_如何学JAVA


Please see the PHP Manual on Classes and Objects. $this refers to the object instance. Also see these questions:

  • What does the variable $this mean in PHP?
  • What is the meaning of $this

For array($this,'some_function') see the PHP manual on callbacks. In methods and functions that do accept callbacks, like call_user_func, it means call the method some_function on $this. See

  • How do I implement a callback in PHP?
  • What is a callback function and how do I use it with OOP

Marking this as CW because it's not meant as an answer but the reason for closevoting as duplicate


$this is a class pointer. $this in class give access to class properties and methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消