Skip to main content

I am not unfamiliar with this parameter in javascriptJavaScript. But in joomla'sJoomla's PHP files, I often come across $this that seems coming from nowhere(Not in an object). To clarify some basic notions, here are some questions:

  1. In JavascriptJavaScript, generally, if this is not inside an object, then it is referring to the global object, which inbrowserin a browser environment is window. I understand that in PHP there is no such thing, but when it comes to what $this is referring to, is there any similar thing?

  2. I think in most cases, for those $this not in an object, they actually reside in an object that is defined in another file, which 'require's current file, am I right? If yes, how can I find out where that file is, or what object $this resides in? Althought usingUsing the extension "J!dump" I can actually see what $this is, but I still want to know how to find out the parent object.

I am not unfamiliar with this parameter in javascript. But in joomla's PHP files, I often come across $this that seems coming from nowhere(Not in an object). To clarify some basic notions, here are some questions:

  1. In Javascript, generally, if this is not inside an object, then it is referring to the global object, which inbrowser environment is window. I understand that in PHP there is no such thing, but when it comes to what $this is referring to, is there any similar thing?

  2. I think in most cases, for those $this not in an object, they actually reside in an object that is defined in another file, which 'require's current file, am I right? If yes, how can I find out where that file is, or what object $this resides in? Althought using extension "J!dump" I can actually see what $this is, but I still want to know how to find out the parent object.

I am not unfamiliar with this parameter in JavaScript. But in Joomla's PHP files, I often come across $this that seems coming from nowhere(Not in an object). To clarify some basic notions, here are some questions:

  1. In JavaScript, generally, if this is not inside an object, then it is referring to the global object, which in a browser environment is window. I understand that in PHP there is no such thing, but when it comes to what $this is referring to, is there any similar thing?

  2. I think in most cases, for those $this not in an object, they actually reside in an object that is defined in another file, which 'require's current file, am I right? If yes, how can I find out where that file is, or what object $this resides in? Using the extension "J!dump" I can actually see what $this is, but I still want to know how to find out the parent object.

Source Link
shenkwen
  • 1.4k
  • 1
  • 12
  • 26

How to find out what $this is?

I am not unfamiliar with this parameter in javascript. But in joomla's PHP files, I often come across $this that seems coming from nowhere(Not in an object). To clarify some basic notions, here are some questions:

  1. In Javascript, generally, if this is not inside an object, then it is referring to the global object, which inbrowser environment is window. I understand that in PHP there is no such thing, but when it comes to what $this is referring to, is there any similar thing?

  2. I think in most cases, for those $this not in an object, they actually reside in an object that is defined in another file, which 'require's current file, am I right? If yes, how can I find out where that file is, or what object $this resides in? Althought using extension "J!dump" I can actually see what $this is, but I still want to know how to find out the parent object.