[Previous] [Contents] [Next]


:: vs. ->, self vs. $this


For people confused about the difference between :: and -> or self and $this, I present the following rules:

  • If the variable or method being referenced is declared as const or static, then you must use the :: operator.

  • If the variable or method being referenced is not declared as const or static, then you must use the -> operator.

  • If you are accessing a const or static variable or method from within a class, then you must use the self-reference self.

  • If you are accessing a variable or method from within a class that is not const or static, then you must use the self-referencing variable $this.


[Previous] [Contents] [Next]