Interface is a class which is defined by interface keyword.

In this article I’m going to explain what is interface and how to use of this in php programming. First of let’s discuss features of interface-

– Interface simple create by interface keyword with name.

– We cannot create object of interface class.

– Interface class implement by implements keyword to other class.

– Interface class can inherit to other interface class by extents keyword.

– One interface class can implement multiple interface class.

– All methods of an interface is abstract.

– All methods of interface automatically treat as a public.

– interface don’t have instance variable.

– If you are implementing interface class you must define all the methods declare in parents class.

– In interface if you are implementing method signature should be same.

– We can’t use private and protected specifire when declaring member of an interface.

Interface swcodes{

function company ();

}

Class developer implements swcodes{

public function company(){

return “Hello company”;

  }

}

Interface can inherit to other interface-

interface company{

//All methods here

}

interface manager {

//All methods here

}

interface developer extends company, manager{

//All methods here

}

By using Interface you can achieve multiple inheritance because in php multiple inheritance doesn’t support.

News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: