Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

jamesjones21
jamesjones21
9,260 Points

Calling a class name when it's not instantiated

I'm trying to understand when they call the class name then the method in PHP oop.

''' Clasname:: methodname();

'''

Can someone explain? Is it the fact that the class doesn't have any properties an doesn't require to be instantiated, so we can use the class name?

1 Answer

I haven't watched the video, but you can do this if the method is static. Static methods can be called without instantiating a class, hence why they are called static. Dynamic methods on the other hand are actually called on an instance of a class which actually an object. If you're wondering "why would you need this?" static methods are really useful for design patterns where you don't need an Object just a class. Like a Utility class that does not affect application state just mutates whatever is passed into the static methods.

Hope that helps.

Cheers,

_Ben