Jump to content

Difference between $this and self?


Go to solution Solved by requinix,

Recommended Posts

Hey guys. I have been learning about what the difference between an object and a class. My understanding is that $this is called only when an object has been created, and self is used within the class(before and object is created)

 

Is that correct?

 

Also is it bad practice to combine static and non-static methods in a class? Thanks! :happy-04:

Link to comment
https://forums.phpfreaks.com/topic/281711-difference-between-this-and-self/
Share on other sites

  • Solution

$this is for the instance/the object, self is for the class. The instance doesn't exist until you create it so only instance methods can use it, while the class exists the whole time so both instance and static methods can use it.

 

And no, it's not a bad practice. Not by a long shot.

$this is for the instance/the object, self is for the class. The instance doesn't exist until you create it so only instance methods can use it, while the class exists the whole time so both instance and static methods can use it.

 

And no, it's not a bad practice. Not by a long shot.

 

Okay. Gotchya! Thank you for the clarification!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.