PHP Interface

PHP Interface

Interfaces allow us to specify what methods/functions of a class should implement. It’s quite 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”.

<?php

 interface Course

 {

  public function showCourse();

 }

 class Course1 implements Course

 {

  public function showCourse()

  {

            echo “Course 1”;

  }

 }

 class Course2 implements Course

 {

  public function showCourse()

  {

            echo “Course 2”;

  }

 }

 $student = new Course1();

 $student->showCourse();

 $student = new Course2();

 $student->showCourse();

?>

Post Your Comments & Reviews

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

*

*