Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between accessing a class method via -> and via ::?

Tags:

php

What is the difference between accessing a class method via -> and via ::?

like image 921
user834780 Avatar asked Jul 08 '11 05:07

user834780


2 Answers

The -> is for accessing properties and methods of instantiated objects. The :: is to access static methods, constants or overridden methods.

For more information:

  • Scope Resolution Operator (::)
like image 187
Francois Deschenes Avatar answered Sep 28 '22 05:09

Francois Deschenes


:: is used for accessing static methods or attributes, so you don't have to instantiate an object of the containing class.

-> is used for accessing methods or attributes of instantiated objects.

like image 33
oezi Avatar answered Sep 28 '22 04:09

oezi