Basic Class Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aristona
Forum Commoner
Posts: 33
Joined: Thu Dec 02, 2010 8:14 am

Basic Class Question

Post by Aristona »

Hi,
A very basic question as I said.

What's the difference between "Class::Page()" and "$class->Page()" ?
Also what kind of benefits do I get by using $this? (Computer related benefits like performance.)

It will be good if you can explain these detailed.

Thanks.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Basic Class Question

Post by Darhazer »

Class::Page() is a call to a static method. Static methods are methods of a class and not of it's instance, and generally they have no state (or at least should not).

$this->Page() is a call to a method of the instance. It makes a lot of difference if you have polymorphism as it call the method of the current instance, which can be any subclass of Class.

I suggest you to google and read about static methods, hiding/minimizing state and polymorphism
Post Reply