Interfaces in PHP

In this tutorial, you will learn about the interface, how the interface is implemented in a class, and how it is very helpful for achieving polymorphism in PHP.



Interface An interface is similar to a class except that it cannot contain code.

Using implements  keyword we can cam implement an interface with a Class. An interface can define method names and arguments, but not the contents of the methods

See the below example on Interface.


See the below example of how to implement it in a class.




 

Questions asked by Interview on Interface on PHP

  1. What is an interface?
  2. What is the difference between Interface and Abstract Class?
  3. Which keyword is used for the implementation interface in a class?

 



Hope this tutorial helps.

Tags: ,