what is interface in php? how it is use?
Answer Posted / nur nahid hasan
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 ? | 19 Yes | 6 No |
Post New Answer View All Answers
How to remove leading and trailing spaces from user input values?
How to create a mysql connection in php?
What is composer json?
What is difference between mysqli and mysql?
Explain PHP?
What is static variable in php?
What does $_files means?
What are the two types of variables?
How to get no. of rows using MYSQL function?
Explain how can we execute a php script using command line?
Is php good for career?
What is the difference between md5(), crc32() and sha1() crypto on php?
Is php free to use?
Tell me what kind of things have you done on the social side?
Is strcmp case sensitive?