what is interface in php? how it is use?

Answer Posted / sanjeev kumar

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 ?    24 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we increase execution time of a php script?

487


Does php use html?

469


Why php was called as personal home page?

536


How do you execute a php script from the command line?

517


What are the encryption functions in php?

556






How does cookies work in php?

522


What are different types of runtime errors in php?

541


How to get a random value from a php array?

544


How the values are ordered in an array?

561


What are the differences between GET and POST methods in form submitting?

558


What do you use php for?

524


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

569


What is a model in php?

528


How to copy a file?

553


How you can update memcached when you make changes to php?

611