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

How to swap two variables without using 3rd temp variable.

495


What is the use of array_count_values() in php?

535


How can I make a script that can be bilingual (supports english, german)?

586


Tell me how can we change the maximum size of the files to be uploaded?

546


Does php need html?

531






What is variable function php?

548


What is mean by an associative array?

535


How to do single and multi line comment in php?

558


What are the steps for the payment gateway processing?

536


What are differences between PECL and PEAR?

513


Applications written to provide a GUI shell for Unix and Linux are called

575


What is the purpose of the '.myd' file extension? What do thes file contain?

540


How is csrf token generated?

507


What's the difference between accessing a class method via -> and via ::?

529


What is php variable?

521