what is interface in php? how it is use?

Answer Posted / sanjeev kumar

Interface: Since we all knows that PHP does not support the
multiple inheritance. But don't worry we have an excellent
idea to do the multiple inheritance in php is Interface.
Interface is just like a class using interface keyword and
contains only function declarations(function with no body).
function is defined in the classes where you call it.

Ex:-

interface FirstInterfName{
function Add();
function Sub(10,5);
}

interface SecondInterfName{
function glbfunc1();
function glbfunc2();
}


class ClassName implements FirstInterfName,SecondInterfName
{
fuction Add()
{
$a = 5;
$a = $a + 1;
echo $a;
}

fuction Sub($a,$b)
{
$c = $a -$b;

echo $c;
}

function glbfunc1()
{
Implements here method...............
}

function glbfunc2()
{
Implements here method...............
}

}

Is This Answer Correct ?    24 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is php easier than node?

722


How to create a directory?

817


Is key exist in array php?

764


What is properties of class?

821


Write a program to display a table of any given number?

703


What is $_ request in php?

713


What is form validation in php?

773


What is the difference between exception::getmessage and exception::getline?

762


How to know user has read the email-php?

732


Tell me what does $_env means?

750


Which Scripting Engine PHP uses?

822


How do http requests work?

725


Define metaphone()?

8498


Tell me are parent constructors called implicitly inside a class constructor?

763


What is the difference between nowdoc and heredoc?

755