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 are php sessions stored?

696


Can we embedded directly PHP code into XHTML document? State Whether True or False?

1470


Is php harder than javascript?

624


What are the differences between php constants and variables?

666


Why do we use htaccess

778






What is php stack?

683


What enctype is required for file uploads to work?

679


Where is session value stored?

709


How do you destroy a particular or all Sessions?

736


What is composer install?

755


How to remove duplicate values from array using php?

700


Why do we use interface in php?

681


Why do we need session?

690


What does $_server mean?

705


Why delimiter is used in mysql?

723