PHP INTERFACES

Sugar babies

PHP INTERFACES

  • Interfaces allow you to specify what methods a class should implement.
  • Interfaces make it easy to use a variety of different classes in the same way.
  • When one or more classes use the same interface, it is referred to as "polymorphism".
  • Interfaces are declared with the interface keyword
  • Interfaces allow you to specify what methods a class should implement. 

FOUR MAIN USER OF INTERFACE IN PHP :

  • Graphical user interface 
  • Command line interface 
  • Menu-driven user interface
  • Touchscreen Graphical User Interface.

EXAMPLES OF INTERFACES IN PHP :

  • Computer mouse.
  • Remote control.
  • Virtual reality.
  • ATMs.
  • Speedometer.
  • The old iPod click wheel.

SYNTAX FOR INHERITANCE IN PHP :

interface <interface_name>
 {
 // declare constant fields 
// declare methods that abstract // by default.
 } 

EXAMPLE FOR INTERFACES IN PHP :

<?php
interface Animal  {
    public function make Sound ( ) ;
}
class Cat implements Animal  {
    public function make Sound ( )  {
         echo   "Meow";
     }
}
$animal  =  new  Cat ( ) ;
$animal->make Sound ( ) ;
?>

OUTPUT :

Meow 
Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send