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

When to use self over $this?

557


What are the different types of PHP arrays?

571


What is php compared to html?

543


Is php a mvc?

511


Explain about objects in PHP?

577






what are the differences between php and perl

1609


So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?

554


How to replace a substring in a given string?

556


Can php run without server?

560


What are the advantages of php?

539


What is $row in php?

539


How to get the total number of values in an array?

523


What is memcache?

544


What are the features of php?

556


What is the use of callback in php?

516