Differences between abstract class and interface in PHP

Following are some main difference between abstract classes and interface in PHP

  1. In abstract classes, this is not necessary that every method should be abstract. But in interface every method is abstract.
  2. Multiple and multilevel both type of inheritance is possible in the interface. But single and multilevel inheritance is possible in abstract classes.
  3. The method of PHP interface must be public only. A method in an abstract class in PHP could be public or protected both.
  4. In an abstract class, you can define as well as declare methods. But in the interface, you can only define your methods.

For more information about abstract classes and Interface in PHP you can read:
http://en.wikipedia.org/wiki/Interface_%28computing%29
http://php.net/manual/en/language.oop5.interfaces.php
http://php.net/manual/en/language.oop5.abstract.php

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

WordPress.com.

Up ↑

%d bloggers like this: