eldan88 Posted August 30, 2013 Share Posted August 30, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/281711-difference-between-this-and-self/ Share on other sites More sharing options...
Solution requinix Posted August 30, 2013 Solution Share Posted August 30, 2013 $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. Quote Link to comment https://forums.phpfreaks.com/topic/281711-difference-between-this-and-self/#findComment-1447476 Share on other sites More sharing options...
eldan88 Posted September 1, 2013 Author Share Posted September 1, 2013 $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! Quote Link to comment https://forums.phpfreaks.com/topic/281711-difference-between-this-and-self/#findComment-1447616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.