Interface in php

Interfaces in php provide a way for defining contracts to which a class adheres; the interface provides method prototypes and constants, and any class that implements the interface must provide implementations for all methods in the interface.

Here’s the syntax for an interface definition:

interface interfacename
{
[ function functionname();

]
}

To declare that a class implements an interface, include the implements keyword and any number of interfaces, separated by commas:

interface Printable
{
 function printOutput();
}
class ImageComponent implements Printable
{
 function printOutput()
 {
 echo "Printing an image...";
 }
}

An interface may inherit from other interfaces (including multiple interfaces) as long as none of the interfaces it inherits from declare methods with the same name as those declared in the child interface

Leave a Comment