Results 1 to 2 of 2

Thread: differences between "self", "$this", "::" and "->" and when / how to use them

  1. #1
    Join Date
    Apr 2014

    differences between "self", "$this", "::" and "->" and when / how to use them

    I am Struggling to understand the differences between "self", "$this", "::" and "->" and when / how to use them in classes. Any help would be appreciated, also if you could dumb it down to plain english that would help alot! Thanks in advance

    (In what I've been reading it's been saying stuff about static methods stuff and I'm not sure when / how this influences it - am I going down the wrong path?)

  2. #2
    Join Date
    Aug 2004
    "self" (and "parent") essentially refer to a class in general, while "$this" refers to the specific instance of the class, i.e. "this object". The "->" operator is used with objects, so will be what follows "$this", while the "::" operator is used with the more general class reference, so will be used with "self" (or "parent").

    "self" is used in a static context, either within a static method, or to reference a static class variable anywhere within a class, while "$this" refers only to the current instance (object), so would be used in any non-static method (which generally is the more common case).

    The "::" operator is similarly used to call a static method or parameter from outside of the class, e.g. "ClassName::methodName()".
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center