PHP5 $this variable

Anybody’s think and wonder what $this variable mean in PHP, will $this variable is a pointer to the object making the function call. $this variable is not available in static methods. In this post you will know how $this variable important specially in PHP OOP.

Here is the sample:

In the above example, $rys1 and $rys2 are two separate ryscript objects. Each object has its own memory to store names. But if you see the function DisplayName() is common. During run time, how can it make a difference as to which memory location to use to store the function values. Therefore, it uses the $this variable. As mentioned earlier, $this variable is a pointer to the object making a function call.

Therefore when we execute $rys1->DisplayName(“ryan”), $this in the DisplayName() function is a pointer or a reference to the $rys1 variable.

Hope this post will help you in your PHP project or school web project.

by Ryan Sutana

  • I can’t realize exactly how I found this site simply because I was studying details on Real-estate within Longwood, Fl, but at any rate, I have had an enjoyable time looking through that, thanks!

  • hey there and thanks in your info ? I have certainly picked up anything new from proper here. I did however expertise some technical issues the use of this site, since I experienced to reload the website lots of times prior to I could get it to load correctly. I were thinking about if your web host is OK? Not that I am complaining, however slow loading circumstances times will often impact your placement in google and could harm your quality ranking if ads and marketing with Adwords. Anyway I am adding this RSS to my email and can glance out for much more of your respective fascinating content. Make sure you update this once more very soon..

  • Valuable information and exceptional design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up