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
Is apache needed for php?
What is the meaning of php?
What is the difference between the include() and require() functions?
What is mysqli_real_escape_string?
What does trim () do in javascript?
How can you declare the array in php?
What is the use of $_server["php_self"] variable?
Why is php used for web development?
What is preg_match?
What is the difference between array_merge() and array_merge_recursive() in php?
What are default session time and path?
What is a substring in php?
Should I use mysqli or pdo?
What are the different types of php variables?
What is the functionality of the functions strstr() and stristr()?