What is interface in php

Object Oriented Programming

Posted on 06 May 15 by Vickey
  543



Interface is a class or we can say base class which is implement in a child calss. We defined interface by using keyword interface. all method or function of a interface should be public according the nature of interface.Function in interface does not have any functionality these are overwride in child class and these are necessary to use child class

interface setTemplate
{
    public function setVar($var);
    public function getVar($var);
}

class template implements setTemplate{

    fuction setVar($var){

        function body.......

    }

    fuction getVar($var){

        function body.......

    }
}

if we does not use all function of a interface then it will give erorr

class template implements setTemplate{

    fuction setVar($var){

        function body.......

    }
}

the above code will return error

like abstract class we can create object of a interface we only implement it in a child class


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com