Home >> PHP >> What is interface in PHP

What is interface in PHP

Interface(Mediator or Contractor or Broker):-
Interface is a mediator or also you can say that blueprint of class and we can not create the object of interface and we can have only abstract type of method in interface.
*interface keyword
Example:-

interface abc{
     public function xyz($a);
}
Creating interface with name abc.

*You can implements your interface in your class using implements keyword.let us implement our interface abc in our class.
Example:-

class test implements abc{
      public function xyz($a){
            //Your function body
      }
}

*One interface extends multiple interface using extends keyword.
Example:-

interface i1{
     public function f1();
}
interface i2 extends i1{
     public function f2();
}
class abc implements i2{
      public function f1(){
            //Your function body
      }
      public function f2(){
            //Your function body
      }
}

Post Your Comment

Next Questions
What is difference between abstract class and interface
What is inheritance
Inheritance types
What is single inheritance
What is multiple inheritance
What is multilevel inheritance
How to use static method and property in inheritance
How to use self and parent with static
How to use self and parent without static
What is visibility
What is the difference between public, private, and protected
What is final
What is final class
What is final method
What is final variable
How to print half pyramid using star
How to print half pyramid using number
How to print inverted half pyramid using star
How to print inverted half pyramid using number
How to print half pyramid using one to ten number
How to print pyramid pattern using star
How to print half pyramid pattern using star
How to print half pyramid pattern using star after 180 degree rotation
display errors
string to array

Copyright ©2022 coderraj.com. All Rights Reserved.