Jump to content

Difference between $this and self?


eldan88

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

$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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.