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


Please Help Members By Posting Answers For Below Questions

Which php framework is best?

735


How can we enable error reporting in php?

696


How to include variables in double-quoted strings?

705


How can we display the output directly to the browser?

727


What is the string concatenation operator in php?

744


How is session data stored?

697


Can we use get instead of post?

714


How can we pass the variable through the navigation between the pages?

736


What is php session_start() and session_destroy() function?

796


What is the Pipe Symbol represented?

806


How to access a specific character in a string using php?

751


What language is php written in?

814


What are the differences between GET and POST methods?

739


Do you know how to enable error reporting in php?

693


What is the difference between explode () and split () functions in php?

883