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

Which is better python or php?

743


What is htmlspecialchars?

744


I need to know about the courses which are useful in corporate companies.. especially php/mySQL, Java/j2ee, .NET.. also tell if any other courses are valuable

1737


Is php class name case sensitive?

723


What are the environmental variables?

789


What is properties of class?

793


Is multilevel inheritance possible in php?

737


What is the difference between for and foreach loop in php?

841


What is encapsulation in php with example?

783


How check variable is set or not in php?

643


write a prog using insert,update,delete in this manner as output? name: phno. add button 1.name phno. edit button delete button 2.

1785


What is uri routing?

718


What is the use of addslashes in php?

705


What is php and its features?

709


Tell us why did you choose this particular career path?

713