Oliver Chalk Oliver Chalk - 5 months ago 8
PHP Question

In PHP when do I use :: and when do I use ->

I apologise if this seems obvious to the more experienced PHP users, however, I do believe I have missed an important block in my learning journey. When using objects, how do I now to call the function through -> or call it using :: . At the moment I have only been using the -> method however I have come across code using the :: method. Any insight or explanation is greatly appreciated!



-> is for objects method and properties so when you create object of class you need to use ->

$someObject = new someClass();

:: is for static method and properties of class, which means you do not need to create object to use it: